Play videoPlease edit your post.
For large amounts of code, attach it.
- What are Function return values ? How do I use them ? - MQL4 forum
- For a Buy, when the Bid goes below the SL, the order is closed. Your OrderSelect fails. There is no true or false.
I am coding an Expert Advisor and I need a good way to detect stop loss.
I have written this function but I'm not sure whether it would work correctly. Can someone help me with this?
The function returns and integer to specify whether the order is BUY or SELL and whether stop loss is TRUE or FALSE.
If you are OrderSelect() ing your order by position then use a position not a ticket number. To select an Order by ticket it will be selected regardless of it being open or closed, if you want to select by position you need to specify the Order pool, read the documentation for OrderSelect()
For a closed order check the OrderClosePrice() compared to the OrderStopLoss(), if they are close then it's a good probability that the order was closed by SL.
Can you please elaborate on the difference between position and ticket number?
The ticket number is a unique number given to the Order by your Broker, the position number is the position of the Order in your pool of orders, if you have 2 open orders they will be at positions 0 and 1 in the Order pool, there is also the History pool that holds your closed orders, if you have 100 closed orders they will be at positions 0, 1, 2, 3, 4, . . . 98, 99 they will all also have their own unique ticket numbers.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am coding an Expert Advisor and I need a good way to detect stop loss.
I have written this function but I'm not sure whether it would work correctly. Can someone help me with this?
The function returns and integer to specify whether the order is BUY or SELL and whether stop loss is TRUE or FALSE.