I've recently been researching a multi-strategy Expert Advisor (EA) for XAUUSD and encountered an interesting problem. I'd like to hear everyone's thoughts on the underlying mechanisms and implementation.
In MT5, if the EA uses:
OnTick() for high-frequency signal judgment
OnTimer() for risk control and order synchronization
OnTradeTransaction() for updating trade status
and also applies batch BUY STOP / SELL STOP orders on new candlesticks
then in highly volatile markets (especially gold news-driven markets), the following often occurs:
Order status synchronization is incomplete
PositionsTotal() has changed but cached data hasn't been updated
Some orders enter ORDER_STATE_STARTED
TRADE_TRANSACTION_ORDER_UPDATE and DEAL_ADD arrival order is unstable
Simultaneously triggering duplicate orders or risk control misjudgments
This is especially noticeable in ECN environments like Pepperstone, where asynchronous execution is particularly pronounced.
My current confusion is:
Would you completely abandon the trade status judgment in OnTick()?
- Creating Expert Advisors
- Sending a trade request: OrderSend and OrderSendAsync
- Time management in the tester: timer, Sleep, GMT
PositionsTotal() can be out of sync in particular situations. I recomend using https://www.mql5.com/ru/code/16006 library as this deals with many peculairties of the terminal so you do not have to.
But, most likely its bug(s) in your code. I am running 10+ algos within the same EA using async order operations managed/tracked through OnTradeTransaction without any problem. There is no need for OnTimer and the execution logic runs from Ontick again with no problem at all.
MT4Orders
- 2016.08.05
- www.mql5.com
Параллельное использование ордерных систем MetaTrader 4 и MetaTrader 5.
ValerianBlackthorne:
Simultaneously triggering duplicate orders or risk control misjudgments
We have to wait for confirmation by ontradetransation...
Simultaneously triggering duplicate orders or risk control misjudgments
ValerianBlackthorne:
You need to decide what is more important to you - execution speed or confirmed state of the trading environment - because you can't ensure both in highly distributed system. Also I don't think your current implementation scattered in mutiple event handlers meets your requirements about status actualization. I'd work with OnTick only and use OnTimer as a fallback mode (to detect connection losses, for example, or timeouts).
I've recently been researching a multi-strategy Expert Advisor (EA) for XAUUSD and encountered an interesting problem. I'd like to hear everyone's thoughts on the underlying mechanisms and implementation.
In MT5, if the EA uses:
OnTick() for high-frequency signal judgment
OnTimer() for risk control and order synchronization
OnTradeTransaction() for updating trade status
and also applies batch BUY STOP / SELL STOP orders on new candlesticks
then in highly volatile markets (especially gold news-driven markets), the following often occurs:
Order status synchronization is incomplete
PositionsTotal() has changed but cached data hasn't been updated
Some orders enter ORDER_STATE_STARTED
TRADE_TRANSACTION_ORDER_UPDATE and DEAL_ADD arrival order is unstable
Simultaneously triggering duplicate orders or risk control misjudgments
This is especially noticeable in ECN environments like Pepperstone, where asynchronous execution is particularly pronounced.
My current confusion is:
Would you completely abandon the trade status judgment in OnTick()?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register