confussion with Magic number

 

Hi colleagues

I got confused with the purpose of magic number when make order.

I wanted to open two orders at certain time - one of them with little (close to market)  take profit and the other  with much larger.

here is sammple code:

            trReq.magic= MAGIC;

            trReq.volume= Lots;

            trReq.price=tick.ask;              

            trReq.sl=tick.ask+15;     // Stop Loss level of the order

            trReq.tp=tick.ask-500;     // Take Profit level is 500 points

            trReq.type= ORDER_TYPE_SELL_LIMIT;          // Order type

            result = OrderSend(trReq,trRez);

            //now change Magic and send another order

            trReq.magic= MAGIC+1;    //different magic number!

            trReq.sl=tick.ask+15;     // Stop Loss level of the order

            trReq.tp=tick.ask-15;     // Take Profit level is only 15 points

            result = OrderSend(trReq,trRez);


 

 In the tester these orders are executed at the same time. here is a copy from the Journal:

2008.05.29 00:00:00   sell limit 20.00 SPX500 at 1390.5 sl: 1405.5 tp: 1375.5 (1390.5 / 1390.7 / 1390.5)

2008.05.29 00:00:00   sell limit 20.00 SPX500 at 1390.5 sl: 1405.5 tp: 890.5 (1390.5 / 1390.7 / 1390.5)

and  also:

2008.05.29 00:00:40   order [#2 sell limit 20.00 SPX500 at 1390.5] triggered

2008.05.29 00:00:40   deal #2 sell 20.00 SPX500 at 1390.5 done (based on order #2)

2008.05.29 00:00:40   deal performed [#2 sell 20.00 SPX500 at 1390.5]

 

and the same message for the other order....

and here comes the PROBLEM:

soon after, the mentioned  15 point take profit level of one of the orders is hit.   But instead of closing  only half of the position what happens  is  that both position  are  closed at the  mentioned 15 point take profit level, even that half of it was programmed for 500 point take profit. 

here is Journal:

2008.06.03 00:00:40   deal performed [#4 buy 40.00 SPX500 at 1375.5]

2008.06.03 00:00:40   deal #4 buy 40.00 SPX500 at 1375.5 done (based on order #4)

2008.06.03 00:00:40   take profit triggered sell 40.00 SPX500 1390.5 sl: 1405.5 tp: 1375.5 [#4 buy 40.00 SPX500 at 1375.5]

why two orders , with different magic's are closed altogether at the  take profit level of one of them?

could anybody help with this issue? what I do wrong?

thank's !

sincerely yours

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 

adinchi:

...

 
angevoyageur:

Hi angevoyageur,

I have red your link. this obvious is the case - it is only one position in the end with TP from the second order.  that is why I decided to use  different Magic number for these two orders - I thought this is one of the convenience of magic number. But it do not works.  Any  advice, how to resolve this issue?

best regards! 

 
adinchi:

Hi angevoyageur,

I have red your link. this obvious is the case - it is only one position in the end with TP from the second order.  that is why I decided to use  different Magic number for these two orders - I thought this is one of the convenience of magic number. But it do not works.  Any  advice, how to resolve this issue?

best regards! 

You don't have to use SL/TP, as this close all your position. You have 2 choices (at least) :

  1. Use pending orders to simulate your SL/TP for both trades, So for your 2 trades, you have to enter 4 pending orders. The advantage is that it's manage at server side, the disadvantage is that you have to cancel 1 pending order when the other is hit (for example SL pending order if TP pending order is hit).
  2. Manage your trades internally with the EA. Advantage is that you can do all you want but with inconvenient of more complexity. Disadvantage is less security if you loss your connection to server.

Magic Number can be used to identify the deals/orders/positions of your EA, but it's not intended to manage trades

P.S: I edited your first post. Another time use the SRC button when you post code.

Reason: