Download MetaTrader 5

Magic numbers

To add comments, please log in or register
elektor
34
elektor 2011.04.25 13:20 

Hi,

I am having some difficulty understanding the way magic numbers are used in MQL5. If I declare a global variable my_magic = 12345 and then in the onTick() function if I try to place only one buy order would the POSITION_MAGIC, ORDER_MAGIC and the DEAL_MAGIC be the same as my_magic?

If magic numbers(POSITION_MAGIC, ORDER_MAGIC, DEAL_MAGIC) are set by the user who writes an Expert Advisor how can it identify the positions placed by another Expert Advisor who has also set his magic number equal to (as in this example) 12345. Will this not result in a conflict on the trade servers?

Can someone give me a simple EA which places a single buy position with Trade action = TRADE_ACTION_DEAL type and having its magic number = 12345 and show how the magic numbers interact with another Expert advisor who places a single sell position on the same pair having its magic number = 12345.

Regards,

Elektor

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types - Documentation on MQL5
JMRodMartins
238
JMRodMartins 2011.07.05 00:00  
"elektor:

Hi,

I am having some difficulty understanding the way magic numbers are used in MQL5. If I declare a global variable my_magic = 12345 and then in the onTick() function if I try to place only one buy order would the POSITION_MAGIC, ORDER_MAGIC and the DEAL_MAGIC be the same as my_magic?

If magic numbers(POSITION_MAGIC, ORDER_MAGIC, DEAL_MAGIC) are set by the user who writes an Expert Advisor how can it identify the positions placed by another Expert Advisor who has also set his magic number equal to (as in this example) 12345. Will this not result in a conflict on the trade servers?

Can someone give me a simple EA which places a single buy position with Trade action = TRADE_ACTION_DEAL type and having its magic number = 12345 and show how the magic numbers interact with another Expert advisor who places a single sell position on the same pair having its magic number = 12345.

Regards,

Elektor"

 

If you have 2 different Ea's (or the same on different charts) you should have 2 differents magic numbers, I think....

For example, if( myPosition.Select( symbol) && (myPosition.Type() == POSITION_TYPE_BUY) && (myPosition.Magic() == 12345)) {...}, or  

if( myPosition.Select( symbol) && (myPosition.Type() == POSITION_TYPE_SELL) && (myPosition.Magic() == 12345)) {...}.

In this case, you should put the magic number in the order:   

MqlTradeRequest  request;

request.magic = 12345;

....

OrderSend( request,...); 

 

To add comments, please log in or register