|
Close all opened orders
I have a question about how to close all opened trades. That include trades wich were opened manually.
Here is the code:
if(BalanceEquityProtectionLevel > 0 && AccountEquity() <= AccountBalance ()* BalanceEquityProtectionLevel)
{
AllowTrading = false;
Print("Min. Equity Level Reached - Trading Halted For ",Symbol());
// Alert("Min. Equity Level Reached - Trading Halted For ",Symbol());
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
mode=OrderType();
if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Blue); }
if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePri ce(),slippage,Red); }
// }
}
}
The problem is that, If I have opened a few pairs it's not always true that all trades will be closed too. Further more, it happend that EA continue to open another trade despite the parameter allowtrading == false.
I was debugging this thing and noticed that for some reason this code block was not executed for all pairs. Why, I don't know. Does somebody know answer to that?
This block should close all opened orders and prevent further trading.Maybe I could resolve this issue with writting parameter false to a file or something? The problem in this situation is also with pairs that have no opened orders.
Thanks..
Dejan
Last edited by SloForeX; 12-12-2006 at 11:18 AM.
|