Code fetches wrong Order ID
- CTrade
- RefreshRates()
- Function that returns the number of orders in a specified pair
You set exists=true when you find it, but then you keep selecting other orders. Once you exit the loop, you don't know which order is selected.
Drop the exists variable and put the code in the loop.
What WHRoeder is saying is that you continue looping through orders after finding the order that you are looking for. So you are printing details of the last order selected, not necessarily the one that you want.
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1) { exists = true; break; }
You could exit the loop after finding the trade.
What WHRoeder is saying is that you continue looping through orders after finding the order that you are looking for. So you are printing details of the last order selected, not necessarily the one that you want.
You could exit the loop after finding the trade.