21 July 2017
21 July 2017
union LongDouble { long long_value; double double_value; };Unlike the structure, various union members belong to the same memory area. In this example, the union of LongDouble is declared with long and double type values sharing the same memory area. Please note that it is impossible to make the union store a long integer value and a double real value simultaneously (unlike a structure), since long_value and double_value variables overlap (in memory). On the other hand, an MQL5 program is able to process data containing in the union as an integer (long) or real (double) value at any time. Therefore, the union allows receiving two (or more) options for representing the same data sequence.
union LongDouble { long long_value; double double_value; }; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- LongDouble lb; //--- get and display the invalid -nan(ind) number lb.double_value=MathArcsin(2.0); printf("1. double=%f integer=%I64X",lb.double_value,lb.long_value); //--- largest normalized value (DBL_MAX) lb.long_value=0x7FEFFFFFFFFFFFFF; printf("2. double=%.16e integer=%I64X",lb.double_value,lb.long_value); //--- smallest positive normalized (DBL_MIN) lb.long_value=0x0010000000000000; printf("3. double=%.16e integer=%.16I64X",lb.double_value,lb.long_value); } /* Execution result 1. double=-nan(ind) integer=FFF8000000000000 2. double=1.7976931348623157e+308 integer=7FEFFFFFFFFFFFFF 3. double=2.2250738585072014e-308 integer=0010000000000000 */
class Foo { int value; public: string Description(void){return IntegerToString(value);}; //--- default constructor Foo(void){value=-1;}; //--- parameterized constructor Foo(int v){value=v;}; }; //+------------------------------------------------------------------+ //| structure containing Foo type objects | //+------------------------------------------------------------------+ struct MyStruct { string s; Foo foo; }; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- MyStruct a,b; Foo an_foo(5); a.s="test"; a.foo=an_foo; Print("a.s=",a.s," a.foo.Description()=",a.foo.Description()); Print("b.s=",b.s," b.foo.Description()=",b.foo.Description()); //--- Print("b=a"); b=a; //--- Print("a.s=",a.s," a.foo.Description()=",a.foo.Description()); Print("b.s=",b.s," b.foo.Description()=",b.foo.Description()); /* Execution result; a.s=test a.foo.Description()=5 b.s= b.foo.Description()=-1 b=a a.s=test a.foo.Description()=5 b.s=test b.foo.Description()=5 */ }Memberwise copying of objects is performed in the implicit operator.
ENUM_POSITION_REASON | ENUM_DEAL_REASON | ENUM_ORDER_REASON | Reason description |
---|---|---|---|
POSITION_REASON_CLIENT | DEAL_REASON_CLIENT | ORDER_REASON_CLIENT | The operation was executed as a result of activation of an order placed from a desktop terminal |
POSITION_REASON_MOBILE | DEAL_REASON_MOBILE | ORDER_REASON_MOBILE | The operation was executed as a result of activation of an order placed from a mobile application |
POSITION_REASON_WEB | DEAL_REASON_WEB | ORDER_REASON_WEB | The operation was executed as a result of activation of an order placed from the web platform |
POSITION_REASON_EXPERT | DEAL_REASON_EXPERT | ORDER_REASON_EXPERT | The operation was executed as a result of activation of an order placed from an MQL5 program, i.e. an Expert Advisor or a script |
- | DEAL_REASON_SL | ORDER_REASON_SL | The operation was executed as a result of Stop Loss activation |
- | DEAL_REASON_TP | ORDER_REASON_TP | The operation was executed as a result of Take Profit activation |
- | DEAL_REASON_SO | ORDER_REASON_SO | The operation was executed as a result of the Stop Out event |
- | DEAL_REASON_ROLLOVER | - | The deal was executed due to a rollover |
- | DEAL_REASON_VMARGIN | - | The deal was executed after charging the variation margin |
- | DEAL_REASON_SPLIT | - | The deal was executed after the split (price reduction) of a stock or another asset, which had an open position during split announcement |