I'm currently encountering the following problem:
- BAR 1 : I have an open position and 2 pending orders (Profit Target and Stop Loss) not attached to the order (not within the order, i.e as separate orders).
- BAR 2 : On opening of the bar, Stop Loss is touched and position is closed, however OnTradeTransaction() is not called ! The OnTick() event handler is first called (as there is a new quote), then the OnTradeTransaction() event handler is called. However my order management system is only updated through OnTradeTransaction() because it needs to know what has been executed and what hasn't. In this example, if OnTradeTransaction() had been called first, I would have known with MqlTradeTransaction.type what had happened and updated my strategy, knowing that the order had been filled, and the position closed.
To make it short, is there any way to prioritize the OnTradeTransaction() event on the OnTick() event.
No. The events are synchronous, you can't change their order.
Your possible solution could be not using OnTick at all. Instead, call SymbolInfoTick from OnTradeTrsaction to get latest known tick data.
Here I have a limit order that has been executed on the open of a new tick/bar, and the OnTick() event is first called, then the OnTradeTransaction(). Thus my system is unaware that a trade has been executed and proceeds to finding new conditions to open/close orders.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello all,
I'm currently encountering the following problem:
- BAR 1 : I have an open position and 2 pending orders (Profit Target and Stop Loss) not attached to the order (not within the order, i.e as separate orders).
- BAR 2 : On opening of the bar, Stop Loss is touched and position is closed, however OnTradeTransaction() is not called ! The OnTick() event handler is first called (as there is a new quote), then the OnTradeTransaction() event handler is called. However my order management system is only updated through OnTradeTransaction() because it needs to know what has been executed and what hasn't. In this example, if OnTradeTransaction() had been called first, I would have known with MqlTradeTransaction.type what had happened and updated my strategy, knowing that the order had been filled, and the position closed.
To make it short, is there any way to prioritize the OnTradeTransaction() event on the OnTick() event.
Thanks in advance,
Sk