Is this the correct implementation of OrderClose()
?
for(int ii = 0; ii < OrdersTotal(); ii++)
{
if(OrderSelect(ii, SELECT_BY_POS, MODE_TRADES))
{
if(OrderType() == OP_BUY && OrderMagicNumber() == MagicStart && OrderSymbol() == symb)
{
int tikt = OrderTicket();
if(!OrderClose(tikt,OrderLots(),bid,4,clrPurple))
{
Print("Close Error", GetLastError());
}
}
if(OrderType() == OP_SELL && OrderMagicNumber() == MagicStart && OrderSymbol() == symb)
{
int tikt = OrderTicket();
if(!OrderClose(tikt,OrderLots(),ask,4,clrPurple))
{
Print("Close Error", GetLastError());
}
}
}
}
I am using this code right before opening a trade. For example, if there is a signal to buy then it closes the sell first and then opens a buy, and if there is a sell signal then it closes a sell first and then opens a buy.
But it only does this for the first time and wont work after that. Let's say there is a sell signal. Then it will close the buy and open the sell, but when there is a second signal for a buy then it won't close the sell neither will it open a buy.
There is no error in the experts tab. The only thing I receive in the experts tab is a message like this: Positions order mismatch
. It does not appear like an error or a warning, it just appears as a message.