Problem closing ALL positions
KAF
One of the many differences between demo & the rough and tumble of live trading!
You have to handle delays on the server, price changes between calls to OrderClose
So consider calling the loop several times, with a RefreshRates() just before each OrderClose
Good Luck
-BB-
Ok. Thanks a lot BB
Do you have the same problem. When my EA closes ALL positions in Demo it works fine. But with my real account Alpari UK, nearly every two times it lefts open positions.
Any idea ? thanks
Total=OrdersTotal();if(Total>0 && Error!=0)
{
for(i=Total-1; i>=0; i--)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == TRUE)
{
Pos=OrderType();
if(Pos==OP_BUY){Result=OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, White);}
if(Pos==OP_SELL){Result=OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, White);}
if((Pos==OP_BUYSTOP)||(Pos==OP_SELLSTOP)||(Pos==OP_BUYLIMIT)||(Pos==OP_SELLLIMIT)){Result=OrderDelete(OrderTicket(), White);}
if(Result!=true){Error=GetLastError();Print("LastError = ",Error); }
else Error=0;
}
}
}