Finding out when a trade goes to stop loss

 

Using Limit orders to scale out partial profit implies that I must cancel these limit orders if the base trade goes to stoploss.

I checked OnTrade()  and OnTradeTransaction() but did not get any wiser.  Constantly monitoring the "base" trade seems an awkward way of doing it.

Advise someone?

 
ingvar_e:

Using Limit orders to scale out partial profit implies that I must cancel these limit orders if the base trade goes to stoploss.

I checked OnTrade()  and OnTradeTransaction() but did not get any wiser.  Constantly monitoring the "base" trade seems an awkward way of doing it.

Advise someone?

Yes, you have to learn to use OnTradeTransaction(), not a trivial task though : Detect stop trigger in OnTradeTransaction backtest
 

Agree, not trivial. I think I will save the ticket number for the "Base" transaction in the comment section of the limit out order(s). The time between an actual SL of the base order

and coming close to the limit out order(s) gives me time to check  my current limit orders and check if the base order still is alive, I have a timing routine for 1 minute. And if I am late on some occasion

that can be handled.  There should never be a position for an order containing a ticket number. Just kill it if it appears

Love your comment in the post you linked to:

"Dont religiously believe what a computer tells you"  :-)

 
ingvar_e:

Agree, not trivial. I think I will save the ticket number for the "Base" transaction in the comment section of the limit out order(s). The time between an actual SL of the base order

and coming close to the limit out order(s) gives me time to check  my current limit orders and check if the base order still is alive, I have a timing routine for 1 minute. And if I am late on some occasion

that can be handled.  There should never be a position for an order containing a ticket number. Just kill it if it appears

Love your comment in the post you linked to:

"Dont religiously believe what a computer tells you"  :-)

 
It is actually simpler than that. Just check if there is a position alive for the pair in question. If not kill all pending orders for that pair. Coded it. Works if the "base" order is a market order and that is what I use.
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
 
ingvar_e:
It is actually simpler than that. Just check if there is a position alive for the pair in question. If not kill all pending orders for that pair. Coded it. Works if the "base" order is a market order and that is what I use.
Works only if your EA is alone. No other EA, no manual trading on this pair.
Reason: