I code an EA that sends 4 orders at the time, one buy and 3 buystops.
Now I want EA to close and delete all orders if number of orders is less
than 3(lets say buy order hits sl, and now i have 3 pending orders).
At the end of the code i have:
--------------------------------------------------
void Close_all()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if (OrderSymbol()==Symbol() )
if (OrderMagicNumber()==MagicNumber )
{
if (OrderType()==OP_BUY) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if (OrderType()==OP_SELL) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if (OrderType()==OP_BUYSTOP) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if (OrderType()==OP_SELLSTOP) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
}
return;
}
----------------------------------------------------
Than at the expert start function I have:
int start()
{
if(OrdersTotal()<=3) Close_all();
-------------------------------------------------------
Now this works great when I start backtest, but after sometime,
orders just get closed at some minimal loss constantly, and then later
after some few houndreds closed orders, start to work normaly again!!!
Im lost, any ideas!
Now I want EA to close and delete all orders if number of orders is less
than 3(lets say buy order hits sl, and now i have 3 pending orders).
At the end of the code i have:
--------------------------------------------------
void Close_all()
{
int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
bool result = false;
if (OrderSymbol()==Symbol() )
if (OrderMagicNumber()==MagicNumber )
{
if (OrderType()==OP_BUY) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if (OrderType()==OP_SELL) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
if (OrderType()==OP_BUYSTOP) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Red );
if (OrderType()==OP_SELLSTOP) result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red );
}
}
return;
}
----------------------------------------------------
Than at the expert start function I have:
int start()
{
if(OrdersTotal()<=3) Close_all();
-------------------------------------------------------
Now this works great when I start backtest, but after sometime,
orders just get closed at some minimal loss constantly, and then later
after some few houndreds closed orders, start to work normaly again!!!
Im lost, any ideas!
forexflash