No trade operation error

 

Hi, 

I am trying to publish my EA and am getting a no trade operation error. If I take this following code out

if(size > volMax) size = volMax;
if(size < volMin) size = volMin;

then trade operation occurs but I get an error of invalid volume

  double volume  = 0;
  double volMin = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN);
  double volMax = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX);
  double volStp = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP); 

bool dublicate_trade1 = false;

   if(EA_state_ == 1) dublicate_trade1 = dublicate_trade; if(EA_state_ == 2){ dublicate_trade1 = true; long_button = ObjectGetInteger(ChartID(),"BUY_button",OBJPROP_STATE);  short_button = ObjectGetInteger(ChartID(),"SELL_button",OBJPROP_STATE); };




   //------------------------

// Rule: Long entry

//------------------------

   bool dublicate_trade1 = false;

   if(EA_state_ == 1) dublicate_trade1 = dublicate_trade; if(EA_state_ == 2){ dublicate_trade1 = true; long_button = ObjectGetInteger(ChartID(),"BUY_button",OBJPROP_STATE);  short_button = ObjectGetInteger(ChartID(),"SELL_button",OBJPROP_STATE); };



   



 

   

   if((LONG && EA_state_ == 1 && max_trade_L  && spread_  && buy) || ( EA_state_ == 2 && long_button == 1 ))

     {



      // Action #1

      // Enter at Market

      openPrice = 0;  //Open at current market price

      if(EA_state_ == 1) sl = sl_L; if(EA_state_ == 2) sl = ObjectGetDouble(ChartID(),"SL_target",OBJPROP_PRICE);

      if(EA_state_ == 1) pt = tp_L; if(EA_state_ == 2) pt = ObjectGetDouble(ChartID(),"TP_target",OBJPROP_PRICE);

      size = sqMMRiskFixedAccountPct(symbol_,ORDER_TYPE_BUY,openPrice,sl,mmRiskPercent,mmDecimals,sl,mmLotsIfNoMM,mmMaxLots);


       if(size > volMax) size = volMax;

       if(size < volMin) size = volMin;

      

      // size = NormalizeVolume1(size);

      _ticket = openPosition(

                   ORDER_TYPE_BUY, // Order type

                   symbol_, // Symbol

                   size, // Size

                   openPrice, // Price

                   sl, // Stop Loss

                   pt, // Profit Target

                   correctSlippage(sqMaxEntrySlippage, symbol_), // Max deviation

                   CustomComment, // Comment

                   MagicNumber, // MagicNumber

                   ExpirationTime, // Expiration time

                   false, // Replace existing (only for pending orders)

                   dublicate_trade1  // Allow duplicate trades

                );      


 //   _ticket = OpenOrder(symbol_,size,ORDER_TYPE_BUY,bid(symbol_),sl,pt,CustomComment,false);



      if(_ticket > 0)

        {

         // order was successfuly opened, set or initialize all its exit methods (SL, PT, Trailing Stop, Exit After Bars, etc.)



         //Check StopLoss & ProfitTarget

         //sqCheckSLPT(_ticket, sl, pt);

       //   ObjectSetInteger(ChartID(),"BUY_button",OBJPROP_STATE,0);



        };

     };

The EA is fully functional on my terminal.

Any suggestion? 

Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
All requests to execute trade operations are sent as a structure of a trade request MqlTradeRequest using function OrderSend() . The function...
 
I also tried to use this function but I still had no trade operation error. 
double NormalizeVolume1(double pVolume) {
   double volume  = 0;
   double volMin = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN);
   double volMax = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX);
   double volStp = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);

   if(pVolume > 0) {
     if(pVolume < volMin) volume = volMin; 
      volume = MathRound(volume / volStp) * volStp; // Notice how "volume" is the correct first operand of MathRound and not "pVolume"
     if(pVolume > volMax)  volume = volMax;          // Again, notice how "volume" is the correct second operand of MathMin and not "pVolume"
   } else
      volume = volMin;

   return(volume);
};