How about using a function like the following at every tick for closing opened orders at their stop losses?
A newbie, needs confirmation from experienced coders.
for(int i = 1; i <= OrdersTotal(); i++)
if(OrderType() == OP_SELL || OrderType() == OP_BUY)
OrderClose(OrderTicket(), OrderLots(), OrderStopLoss(), 0);
Always count down when closing orders.
What is the point of your function?
If the price has hit the stop loss, it will already be closed.
If it hasn't, then you will be trying to close at an invalid price.
Ok ... see, got, thanks a lot.
You do agree with some posters here saying that both of them (SL and OrderClose function) should be used for the same order?
I agree that when it is intended that a trade be closed by the EA at a certain level, there should also be an emergency SL in place.
Thanks to all here shared their experiences.
For example, let's say I have a long EURUSD position and its stop loss is at 1.1350.
In OnTick(), the most common way to use OrderClose() looks like the following, isn't it?
if(Bid <= 1.1350) OrderClose("Ticket", "Lots", Bid, 0);