Problem with Multiple Orders Open in EA
Results 1 to 2 of 2

Thread: Problem with Multiple Orders Open in EA

  1. #1
    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!

  2. #2
    You should check the current opened orders instead of increasing/decreasing your own countBuy/countSell... The way you're doing reset the counting in the event you change TFs or reload the EA while orders are opened... And the count isn't diminished if a trade has been closed by TP or SL.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.