Knowing when certain orders are triggered

 

hellow,

Probably this is a newbie question but here we go.

I regardless the discussion whether this is a good idea or not, what I want to do is the following as below :

Instead of a stoploss, once my long or short order is triggered I want to set a sellstop (in case the long order is triggered) or a buystop (in case of a short order is triggered).

So the first situation is that in the beginning of the EA I set a buystop and a sellstop (first part of the image), once either the buystop or sellstop is triggered I want to put a 'counterorder' on a certain defined distance, instead of a stoploss let's say.


using this principle, i need to know which order has been triggered, in order to call the proper function (putting either the sellstop or buystop), but I don't know how to do that.


The final EA is a lot more complex than this, but this is the principle (knowing which order is triggered and based on that call a function).


Could somebody please be so kind to help me out plz?


thanks a lot.

 
giobenoni:

hellow,

Probably this is a newbie question but here we go.

I regardless the discussion whether this is a good idea or not, what I want to do is the following as below :

Instead of a stoploss, once my long or short order is triggered I want to set a sellstop (in case the long order is triggered) or a buystop (in case of a short order is triggered).

So the first situation is that in the beginning of the EA I set a buystop and a sellstop (first part of the image), once either the buystop or sellstop is triggered I want to put a 'counterorder' on a certain defined distance, instead of a stoploss let's say.


using this principle, i need to know which order has been triggered, in order to call the proper function (putting either the sellstop or buystop), but I don't know how to do that.


The final EA is a lot more complex than this, but this is the principle (knowing which order is triggered and based on that call a function).


Could somebody please be so kind to help me out plz?


thanks a lot.

Have a look at this:

https://www.mql5.com/en/docs/event_handlers/ontradetransaction

Documentation on MQL5: Event Handling / OnTradeTransaction
Documentation on MQL5: Event Handling / OnTradeTransaction
  • www.mql5.com
OnTradeTransaction - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Documentation on MQL5: Event Handling / OnTrade
Documentation on MQL5: Event Handling / OnTrade
  • www.mql5.com
OnTrade - Event Handling - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: