Stop Loss of current trade and a stop order for a new trade at the same price, how does the OnTrade function react?

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
Hey guys, I'm currently working on an expert advisor, in which I use the OnTrade() function to trigger chart object creation functions. Basically, I want to manually draw arrows and lines on the chart, somewhat similar to how the native trade entry/exit arrows and sl/tp lines work. In order to do so, I first check in the OnTrade function if there is a relevant open position, if there is, I get the position ticket, if not, the position ticket is 0. So, if I get a non 0 position ticket, I get the position details, such as open price, tp, sl, position open time, etc. and use those values to draw on the chart. On the other side the same, if I get a 0 position ticket, I assume that either the OnTrade event got triggered by opening an order, which I check for, or, the position just got closed, in which case I again want to get the details of the last position and draw on the chart.
Now, the follwing problem: What happens if there is an open position with a stop loss price of x, and a stop or limit order at the same price? Can I be sure that there is a moment where my getPositionTicket function returns 0 in order to detect the closing of the last position? Or is it even possible that the new position gets executed before the last one gets successfully closed and I therefore never get a 0 position ticket and never detect the closing of the position in the first place? And if thats the case, what would be ways to work around that? Heres the relevant snippets of my code: