Closing Market Orders

 

I am running my EA on Demo, but I am unable to make any progress at the point where the existing market order is instructed to close.

The instructions from the strategy are being generated correctly at the start of each new bar and my various alerts are as follows:

Number of orders=1

Ticket=2426438 Lot=0.1 Type=1

CloseSell=1 OpenBuy=1

Attempt to cose Sell 2426438 waiting to respond

MODE_DIGITS=12 (can this be right???)

Answer=0

At this point the order is not closed. The closing code is as follows:

//Closing orders
while(true)
{
if(Type==0 && CloseBuy==true)
{
Alert("Attempt to close Buy ",Ticket," Waiting for response...");
RefreshRates();
Alert(MODE_DIGITS);
Ans=OrderClose(Ticket,Lot,NormalizeDouble(MarketInfo(OrderSymbol(),MODE_BID),MarketInfo(OrderSymbol(),MODE_DIGITS)),10);
GetLastError();
Alert("Answer=",Ans);
if(Ans==1)
{
Alert("Closed order Buy",Ticket);
break;
}
if((GetLastError())==1)
continue;
return;
}
if(Type==1 && CloseSell==true)
{
Alert("Attempt to close Sell ",Ticket," Waiting for response...");
RefreshRates();
Alert(MODE_DIGITS);
OrderSelect(Ticket,SELECT_BY_TICKET);
Ans=OrderClose(Ticket,Lot,NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)),10);
Alert("Ticket=",Ticket," Lot=",Lot," Type=",Type);
GetLastError();
Alert("Answer=",Ans);
if(Ans==1)
{
Alert("Closed order Sell",Ticket);
}
if((GetLastError())==1)
continue;
return;
}
break;
}

I welcome any suggestions as to why this is not working.

 

MODE_DIGITS is indeed 12, what were you expecting when you output a constant ? oh, maybe you meant to output MarketInfo using MODE_DIGITS ?

Calling GetLastError clears the error . . so when you call it a second time it is empty . . . Print it out so you know it's value . . . you need to know why the OrderClose failed . .

As you are selecting the order . . why not use OrderLots & OrderClosePrice (in place of NormalizeDouble(MarketInfo(OrderSymbol(),MODE_ASK),MarketInfo(OrderSymbol(),MODE_DIGITS)) )

 
Reason: