I am just a newbie in MQL4 and recently I have been trying to make a simple program. In order to understand the program, I just test the 'delete_pending' script in the sample script, but it doesn't work.
This is how I tested it. I just manually opened a limit buy, and then I run the delete_pending script. I didn't work. The GetLastError() returned 4109 ('Trade is not allowed'). What's wrong with that?
Thank you in advance..
-- This is the script -
int start()
{
bool result;
int cmd,total;
//----
total=OrdersTotal();
//----
for(int i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
//---- pending orders only are considered
if(cmd!=OP_BUY && cmd!=OP_SELL)
{
//---- print selected order
//OrderPrint();
//---- delete first pending order
result=OrderDelete(OrderTicket());
if(result!=TRUE) Print("LastError = ", GetLastError());
break;
}
}
else { Print( "Error when order select ", GetLastError()); break; }
}
//----
return(0);
}
//+------------------------------------------------------------------+
This is how I tested it. I just manually opened a limit buy, and then I run the delete_pending script. I didn't work. The GetLastError() returned 4109 ('Trade is not allowed'). What's wrong with that?
Thank you in advance..
-- This is the script -
int start()
{
bool result;
int cmd,total;
//----
total=OrdersTotal();
//----
for(int i=0; i<total; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
cmd=OrderType();
//---- pending orders only are considered
if(cmd!=OP_BUY && cmd!=OP_SELL)
{
//---- print selected order
//OrderPrint();
//---- delete first pending order
result=OrderDelete(OrderTicket());
if(result!=TRUE) Print("LastError = ", GetLastError());
break;
}
}
else { Print( "Error when order select ", GetLastError()); break; }
}
//----
return(0);
}
//+------------------------------------------------------------------+