Need asistance on fixing on an Ea

 
 could someone please assist me in preventing this EA from opening numerous trades at once
Files:
MarvojsEa.mq4  6 kb
 
Hi, check your strategy code, probably you have Max Trade or Total Open Orders settings to 0 which mean unlimited. Switch number and check on demo how it work, if this solution not work hire a freelance, this solution is cost but you make sure your startegy will be work good. Greg
 
Greg Pawlak:
Hi, check your strategy code, probably you have Max Trade or Total Open Orders settings to 0 which mean unlimited. Switch number and check on demo how it work, if this solution not work hire a freelance, this solution is cost but you make sure your startegy will be work good. Greg
Thanks
 
KARTELO: could someone please assist me in preventing this EA from opening numerous trades at once
  1. Why did you post your MT4 question in the Root / MT5  EAsection instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2.       int buyticket=OrderSend(_Symbol,OP_BUY,LotSize,Ask,Slippage,0,0,"BUY",MagicNumber,0,clrNONE);
          if(buyticket<0){
             Print("OrderSend failed with error #",GetLastError());
            }else{
             Print("OrderSend placed successfully");
            }
          bool res=OrderModify(buyticket,OrderOpenPrice(),Ask-StopLoss*MyPoint,Ask+TakeProfit*MyPoint,0,Blue);
    
    If the order doesn't open, how can you try to modify it?

  3. There is no need to open an order and then set the stops. Simplify your code - do it in one step. TP/SL on OrderSend has been fine for years.
              Build 500 № 9 2013.05.09
              Need help me mql4 guru add take profit to this EA - Take Profit - MQL4 programming forum 2017.09.27

  4. You buy at the Ask and sell at the Bid. So for buy orders you pay the spread on open. For sell orders you pay the spread on close.
    1. Your buy order's TP/ SL(or Sell Stop's/Sell Limit's entry) are triggered when the Bid reaches it. Not the Ask.
    2. Your sell order's TP/ SL(or Buy Stop's/Buy Limit's entry) will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3
    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (Control-O) → charts → Show ask line.)

  5. if(TotalOpenOrders() == 0 && IsNewBar() == true)
    
    if (result != true)//if it did not close
    
    bool res=OrderModify(sellticket,OrderOpenPrice(),Bid+StopLoss*MyPoint,Bid-TakeProfit*MyPoint,0,Blue);
    if(!res)
    
    You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.

  6. Your code Simplified
       if(Low[1] >= MA)
       {
          return(true);
       }
       else
       {
          return(false);
       }
    return Low[1] >= MA;

              Increase Order after stoploss - MQL4 programming forum № 3

  7. while(true)//infinite loop must be escaped by break
    {
       bool result = OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);//actual order closing
       if (result != true)//if it did not close
       {
            Print("LastError = ",GetLastError());//get the reason why it didn't close
       }
    }
    
    If it didn't work the first time, why do you think it will ever succeed? No sleep, no RefreshRates, no exit, no disk space due to log file.
  8. And you never call exitsells.

  9. int TotalOpenOrders(){
       int total_orders = 0;
       for(int order = 0; order < OrdersTotal(); order++){
          if(OrderSelect(order,SELECT_BY_POS,MODE_TRADES)==false) break;
          if(OrderMagicNumber() == MagicNumber && OrderSymbol() == _Symbol)break;
       }
       return(total_orders);
    }
    
    If you find a proper order, you break and return zero. If you don't, the loop exits, and you return zero.
Reason: