I have a problem concerning the amount of orders that EA can start simultaneously. I place the code since it follows:
Inserted Code sinput series MAXORDERS; // Maximum Number of orders open simultaneously extern int buys=5; // Number of buys extern int sells=5; // Number of market orders opened simultaneously int gBuyTicket, gSellTicket; //... int OnInit() //-- double minLot=MarketInfo(_Symbol,MODE_MINLOT); // Check if the input lot is lower than minimum market size if(LOTSlt;minLot) LOTS=minLot; MAX_LOSS=-MAX_LOSS; if(leveragelt;1) leverage=1; if(buyslt;1) buys=1; when (sellslt;1) sells=1; / / /-- return(INIT_SUCCEEDED); //... void OnTick() if (Volume#91;0#93;==1) //... if(/*TRADE CONDITIONS*/ countBuylt;buys) // Open buy order gBuyTicket=OrderSend(_Symbol,OP_BUY,LOTS,Ask,slipp age,0,TP,Market Buy Order Opened,MAGIC,0,clrGreen); countBuy ; // Sell Order Condition if(/*TRADE CONDITIONS*/ countSelllt;sells) // Open market order gSellTicket=OrderSend(_Symbol,OP_SELL,LOTS,Bid,sli ppage,0,TP,Market Sell Order Opened,MAGIC,0,clrRed); countSell ; // Select and Evaluate Orders for(int order=OrdersTotal()-1; ordergt;0; order) if(OrderSelect(order,SELECT_BY_POS)) if(OrderType()==OP_SELL OrderMagicNumber()==MAGIC) if(OrderClosePrice()lt;=OrderTakeProfit()) countSell--; if(/*CLOSING CONDITIONS*/) // Close Order bool closed=OrderClose(OrderTicket(),OrderLots(),Ask,sl ippage,clrGreen); if(closed) countSell--; // Close Buy Order if condition is violated if(OrderType()==OP_BUY OrderMagicNumber()==MAGIC) if(OrderClosePrice()gt;=OrderTakeProfit()) countBuy--; if(/*CLOSING CONDITIONS*/) // Close Order bool closed=OrderClose(OrderTicket(),OrderLots(),Bid,sl ippage,clrRed); if(closed) countBuy--;
It works partly because it unlocks orders but It Doesn't decrease them! So once attained 5 trades for buys and 5 to sells it doesn't trade anymore. I have commented inside the loop for orders to see whether it effectively loops and order factor keeps stack on 1. I cannot figure out why. Can you help me? Thanks!