Closing all orders in deinit function - page 2

 
Volcanbleu:

Hi guys,


I am a bit lost with the deinit function (MT4)..

I want to close all opened orders when something happen that stop the EA, but seems to not do anything. Here is what I wrote but no closing action :


void deinit()
{
   total=OrdersTotal();
   for (cnt = total - 1; cnt >= 0; cnt--)
   ok=OrderSelect(cnt,SELECT_BY_POS);
   if(OrderType()==OP_SELL)
   ok=OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
   if(OrderType()==OP_BUY)
   ok=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
}

Volcanbleu:

Hi guys,


I am a bit lost with the deinit function (MT4)..

I want to close all opened orders when something happen that stop the EA, but seems to not do anything. Here is what I wrote but no closing action :


void deinit()
{
   total=OrdersTotal();
   for (cnt = total - 1; cnt >= 0; cnt--)
   ok=OrderSelect(cnt,SELECT_BY_POS);
   if(OrderType()==OP_SELL)
   ok=OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
   if(OrderType()==OP_BUY)
   ok=OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
}


Please help


Please help

int total=OrdersTotal();
   bool ok;
   for (int cnt = total - 1; cnt >= 0; cnt--) 
   ok=OrderSelect(cnt,SELECT_BY_POS);
   if(OrderType()==OP_SELL)
   ok=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),3,Red);
   if(OrderType()==OP_BUY)
   ok=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),3,Red);