Close all open orders when first order TP hit - page 2

 
andrew #:

1. Loop through OrderHistory and see if any MagicNumber trade closed because of TP.

2. If so, close all other orders with the MagicNumber?

Thank you  andrew - trying to get 1st open order closed by tp seems to be an issue.

Mehmet Bastem #:

It's pretty simple. Assign a custom code to the comment field or a different magicnumber to this first order. After that, if you don't have this magic number, you can close all orders. Or if there is no special code in the comment section, it's like close all orders.

Thank you  Mehmet Bastem - the custom comment suggestion good idea.. am wondering how to give it to first openorder only...mmh

 
katiz22 #:

Thank you  andrew - trying to get 1st open order closed by tp seems to be an issue.

Thank you  Mehmet Bastem - the custom comment suggestion good idea.. am wondering how to give it to first openorder only...mmh

Closed because of TP?
OrderClosePrice() >      OrderOpenPrice()  

And I had an idea not a good idea to use comments field to store info, as brokers sometimes truncate the values?
 
andrew #:
Closed because of TP?
OrderClosePrice() >      OrderOpenPrice()  

And I had an idea not a good idea to use comments field to store info, as brokers sometimes truncate the values?

Yes closed by TP... identifying the first open order, by magic number,symbol when it is closed by TP

 
andrew #: Closed because of TP?
OrderClosePrice() >      OrderOpenPrice() 

This will work only if the TP or SL is never modified. Fails on trailing SLs. This will work only for buy orders.

bool wasClosedTP = MathAbs( OrderClosePrice()-OrderTakeProfit() ) < MathAbs( OrderClosePrice()-OrderStopLoss() );
 
William Roeder #:

This will work only if the TP or SL is never modified. Fails on trailing SLs. This will work only for buy orders.

William Roeder - Thank you so much for this... I do have trailing SL I will test it out see what I can do.