Thread: Ask!
View Single Post
  #382 (permalink)  
Old 10-03-2006, 10:16 AM
Yannis Yannis is offline
Member
 
Join Date: Sep 2005
Location: Athens
Posts: 70
Yannis is on a distinguished road
Mehdi,
Put this code (procedure) outside start() section and when you if the condition is met to close all trades, just call the procedure like that:


int start()
{ // your code here .....
If (your condition here) ShutDownAllTrades();
}

void ShutDownAllTrades
{ int Retry;
While (OrdersTotal()>0)
{ for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)
{ OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderType()==OP_BUY)
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage, Yellow);
Sleep(1000);
}
else if (OrderType()==OP_SELL)
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
RefreshRates();
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage, Yellow);
Sleep(1000);
}
else
{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }
OrderDelete(OrderTicket());
Sleep(1000);
}
}
}
}

HTH

Yannis
Reply With Quote