help - why am I getting:OrderClose error 138 - closing code included in post

 

I keep getting this error when optimizing:

2010.05.18 00:31:40 1999.10.14 13:55 uma test-3.1 USDCHF,H1: OrderClose error 138

I have deleted the history file and re downloaded it 3 times now


here is the closing code:

//close order routine /////////////////////////////////////////////////////////////////////////////////////////////////////

if(OrdersTotal() !=0) // if total orders are not zero
{
int total = OrdersTotal(); // the word total represents total orders
for(i = total - 1; i >= 0; i--)// count each order backwards
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES); //select each order by postiton
if(OrderSymbol() != Symbol()) continue; //if it is not equal to our symbol, skip it
if((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
Print ("time order is open ",(TimeCurrent()-OrderOpenTime()));

if (TimeCurrent()-OrderOpenTime()> order_open_time)
{
OrderClose(OrderTicket(),OrderLots(),10,Red);
Print ("order closed due to time reached");
}
}
}
}
 
bool OrderClose( int ticket, double lots, double price, int slippage, color Color=CLR_NONE)


you are trying to close an order at 10.... USDCHF roughly trades between 0.95 ans 1.33. I guess you missed the closing price in your command


hth

 
Russell:
bool OrderClose( int ticket, double lots, double price, int slippage, color Color=CLR_NONE)


you are trying to close an order at 10.... USDCHF roughly trades between 0.95 ans 1.33. I guess you missed the closing price in your command


hth

fixed it ....sometimes all we need is a good nights sleep !!!!!!!

//close order routine /////////////////////////////////////////////////////////////////////////////////////////////////////

for(int i=OrdersTotal()-1;i>=0;i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol())
continue;

RefreshRates();

if (TimeCurrent()-OrderOpenTime()> order_open_time)
{
Print ("time order is open ",(TimeCurrent()-OrderOpenTime()));
Print ("order closed due to time reached *********************************************************************************");

if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid, 3,White);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask, 3,White);
}
}

//+------------------------------------------------------------------+

 

fixed:

//close order routine /////////////////////////////////////////////////////////////////////////////////////////////////////

if ( (dprice1 <= -close)) buymsg="BUY";
if ( (dprice1 >= close)) buymsg="SELL";



if (sbuymsg != buymsg)
{
sbuymsg=buymsg;

for(int i=OrdersTotal()-1;i>=0;i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol())
continue;

RefreshRates();


if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid, 3,White);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask, 3,White);
}
}

http://sites.google.com/site/dmweadev/

Reason: