Automatic validation. No trade operations error.

 

I have broken down the code to the very basics so it can be publicized. It returns the error shown with automatic validation. What could be the problem?

err

The code follows.

//+------------------------------------------------------------------+
//|                                                     BareBone.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, XXXX"
#property link      "XXXXX"
#property version   "1.1"
#property strict

//---- input parameters
extern double   Lots=0.01;
extern string   StopsSettings="Set stops and restrictions";
extern bool      CloseOnReverseSignal=true;
extern bool OneTradeAtAtime=false;
extern int MaximumTrades=100;
extern string    PSARsettings="Parabolic sar settings follow";
extern double    PsarStep    =0.02;
extern double    PsarMaximum =0.2;
extern int       MagicNumber=3657;
extern bool      BrokerIsFiveDigit=true;

string freeze;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {

   return(0);

  }
//+------------------------------------------------------------------+
//| expert starts                                  |
//+------------------------------------------------------------------+
int start()
  {
double Lts=Lots;
//---------------------------------

//----
   int StopMultd=1,Slip=5;
   if(BrokerIsFiveDigit)StopMultd=10;
   int Slippage=Slip*StopMultd;

//------------------------- Mas--------------------------------------------------
   double PSARlast,PSARprev,LOWnow,HIGHnow,PREVhigh,PREVlow;

// PSAR checks
// PSARnow=iSAR(NULL, 0,Step,Maximum, 0);
   PSARlast=iSAR(NULL, 0,PsarStep,PsarMaximum, 0);
   PSARprev=iSAR(NULL, 0,PsarStep,PsarMaximum, 1);

   LOWnow=Low[0];
   HIGHnow=High[0];
   PREVhigh=High[1];
   PREVlow=Low[1];


//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
   int TotalTrades=Tcount(MagicNumber,Symbol());

   int halt1=0;
   if(OrdersTotal()>0)
     {
      for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders
        {
         if(OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
           {
            if(OrderMagicNumber()==MagicNumber)
              {
               if(OneTradeAtAtime==true){ halt1=1; }
               if(OneTradeAtAtime==false && (OrderOpenTime()>Time[0] || (TotalTrades>=MaximumTrades && MaximumTrades>0))){ halt1=1; }
              }

           }
        }
     }
//-------------------------------------------------------------------+


   int buysignal=0,sellsignal=0;

   if(PSARlast<LOWnow && PSARprev>PREVhigh) buysignal=1;
   if(PSARlast>HIGHnow && PSARprev<PREVlow) sellsignal=1;


//-------------------------------------------------------------------+
// Trade opening
//-------------------------------------------------------------------+
   int buyfail=0,sellfail=0;
 //  if(halt1!=1)
  //   {// halt1

      // Sell criteria
      if(sellsignal==1 && freeze!="Selling trend" && CheckUserInput()!=1) //Signal Sell
        {
         if(CheckMoneyForTrade(NULL,Lts,OP_SELL)==true && CheckVolumeValue(Lts)==true)
           {
            int opensell=OrderSend(Symbol(),OP_SELL,Lts,Bid,Slippage,0,0,"Barebone sell",MagicNumber,0,clrRed);
            if(opensell<1){sellfail=1;}
           }
        }

      // Buy criteria
      if(buysignal==1 && freeze!="Buying trend" && CheckUserInput()!=1) //Signal Buy
        {
         if(CheckMoneyForTrade(NULL,Lts,OP_BUY)==true && CheckVolumeValue(Lts)==true)
           {
            int openbuy=OrderSend(Symbol(),OP_BUY,Lts,Ask,Slippage,0,0,"Barebone buy",MagicNumber,0,clrBlue);
            if(openbuy<1){ buyfail=1;}
           }
        }

  //   }// halt1

   if(buysignal==true){freeze="Buying trend";}
   if(buysignal!=true && sellsignal!=true){freeze="none";}
   if(sellsignal==true){freeze="Selling trend";}

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

//-------------------------------------------------------------------+
// Trade closing
//-------------------------------------------------------------------+


// close buy
   if(sellsignal==1 && CloseOnReverseSignal==true)
     {
      BasClose(MagicNumber,Symbol(),1,0);
     }

// close sell
   if(buysignal==1 && CloseOnReverseSignal==true)
     {
      BasClose(MagicNumber,Symbol(),0,1);
     }




//-------------------------------------------------------------------
   return(0);
  }
//+-----------------------------------

//---------------------------------count trades--------------------------------------------
int Tcount(int tcMagicNumber,string tcSymbol)
  {
   int nTrades=0;
   for(int tc=1; tc<=OrdersTotal(); tc++)
     {

      if(OrderSelect(tc-1,SELECT_BY_POS)==true && OrderSymbol()==tcSymbol && OrderMagicNumber()==tcMagicNumber)
         nTrades++;
     }

   return (nTrades);
  }
//------------------------------------------------------------------------------------



//------------------------Close trades-----------------------------
void BasClose(int CMagicNumber,string CSymbol,int CBuy,int CSell)
  {
   if(OrdersTotal()>0)
     {// orders total
      for(int pb=1; pb<=OrdersTotal(); pb++)
        {// cycle

         if(OrderSelect(pb-1,SELECT_BY_POS)==true && OrderSymbol()==CSymbol && OrderMagicNumber()==CMagicNumber)
           {
            if(OrderType()==OP_BUY&&CBuy==1) bool CloseExec=OrderClose(OrderTicket(),OrderLots(),Bid,50,clrNONE);
            if(OrderType()==OP_SELL&&CSell==1) bool CloseExec2=OrderClose(OrderTicket(),OrderLots(),Ask,50,clrNONE);
           }
        } // cycle
     }// orders total
  }
//---------------------------------------------------------------------


bool CheckMoneyForTrade(string symb,double lots,int type)
  {
   double free_margin=AccountFreeMarginCheck(symb,type,lots);
//-- if there is not enough money
   if(free_margin<0)
     {
      string oper=(type==OP_BUY)? "Buy":"Sell";
      Print("Not enough money for ",oper," ",lots," ",symb," Error code=",GetLastError());
      return(false);
     }
//--- checking successful
   return(true);
  }
//--------------------------------------------------------------------

//+------------------------------------------------------------------+
//| Check the correctness of the order volume                        |
//+------------------------------------------------------------------+
bool CheckVolumeValue(double volume)
  {
   string desc;
//--- minimal allowed volume for trade operations
   double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
   if(volume<min_volume)
     {
      desc=StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume);
      Alert(desc);
      return(false);
     }

//--- maximal allowed volume of trade operations
   double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
   if(volume>max_volume)
     {
      desc=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume);
      Alert(desc);
      return(false);
     }

//--- get minimal step of volume changing
   double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);

   int ratio=(int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
     {
      desc=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f",
                        volume_step,ratio*volume_step);
      Alert(desc);
      return(false);
     }
// description="Correct volume value";
   return(true);
  }
//-------------------------------------------------------------------

//----------check user input and limitations---------------
// return 1 if error is found
int CheckUserInput()
  {
   int result=0;


   if(Lots<=0)
     {
      Print("EA stopped: Check your settings. Lots must have a value.");
      //Reset=1;
      result=1;
     }



   double Minlot=MarketInfo(Symbol(),MODE_MINLOT);
   double Maxlot=MarketInfo(Symbol(),MODE_MAXLOT);
   double MarginNeeded=MarketInfo(Symbol(),MODE_MARGINREQUIRED)*Lots;
   if(Lots<Minlot)
     {
      Print("EA stopped: Lot size cant be lower than ",Minlot," or higher than ",Maxlot);
      //Reset=1;
      result=1;
     }

   if(MarginNeeded>=AccountFreeMargin() && Lots>0)
     {
      Print("EA stopped: Lot size too big for current margin.");
      //Reset=1;
      result=1;
     }

   if(IsTradeAllowed()==false || IsConnected()==false || AccountInfoInteger(ACCOUNT_TRADE_EXPERT)==false)
     {
      Print("Trading not allowed or no connection or experts not allowed");
      result=1;
     }

//------check trades limit---
   if(OrdersTotal()>=(int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS))
     {
      Print("Limit for orders reached.");
      result=1;
     }

   return(result);
  }
//---------------------------------
 
Tonny Obare:

I have broken down the code to the very basics so it can be publicized. It returns the error shown with automatic validation. What could be the problem?

The code follows.

Call the function in OnTick()
 
Mohamad Zulhairi Baba:
Call the function in OnTick()

Still same error.

 
Just passed validation as it is. The only mod was to remove the CheckUserInput() from controlling trades. Demoted it to only give warnings. There must be a small bug in the auto validation.
 
Tonny Obare:
Just passed validation as it is. The only mod was to remove the CheckUserInput() from controlling trades. Demoted it to only give warnings. There must be a small bug in the auto validation.

Can u give us an example your code that pass? i'm very confused right now :(

 

if(OrdersTotal()>=(int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS))
     {
      Print("Limit for orders reached.");
      result=1;
     }

to

if(OrdersTotal()>(int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS))
     {
      Print("Limit for orders reached.");
      result=1;
     }

 
Tonny Obare:

I have broken down the code to the very basics so it can be publicized. It returns the error shown with automatic validation. What could be the problem?

The code follows.

Hello,

the automatic validation working with 'Auto Trading' disabled.

So, try to change this code..

if(IsTradeAllowed()==false || IsConnected()==false || AccountInfoInteger(ACCOUNT_TRADE_EXPERT)==false)


with this one....

if(IsConnected()==false || AccountInfoInteger(ACCOUNT_TRADE_EXPERT)==false)
 

what is wrong with this validation test ?

I reduced my code so that almost nothing is left and I still get this "no trade operation" error 

I even send the above code (with that corrections) and I get this  error again !!!!

someone help please

 
Hossein Zandi:

what is wrong with this validation test ?

I reduced my code so that almost nothing is left and I still get this "no trade operation" error 

I even send the above code (with that corrections) and I get this  error again !!!!

someone help please

I found two threads in rus part of the forum: there are many pages there on those threads, but the general conclusion is the following: this error is related to the coding (minimal lot size checking, for every pair checking and more).
I can not help in coding because I am not a coder sorry.

----------------

I can not send EA for verification. Validation error: no trading operations. - the thread (rus language)

Tortured mistake there are no trading operations -  - the thread (rus language)

 

Hello, i struggle with the same problem...

in my case, the solution was...


1. Check all volume in all orders with this function:

bool CheckVolumeValue(double volume)
  {
//--- minimal allowed volume for trade operations
   double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN);
   if(volume<min_volume)
     {
      
      return(false);
     }

//--- maximal allowed volume of trade operations
   double max_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MAX);
   if(volume>max_volume)
     {
      
      return(false);
     }

//--- get minimal step of volume changing
   double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP);

   int ratio=(int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
     {
    
      return(false);
     }
  
   return(true);
  }

2. And optimized lots with this function:

double LotsOptimized()
  {
   double lot=LotFix;
   int    orders=HistoryTotal();     // history orders total
   int    losses=0;                  // number of losses orders without a break
//--- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*MaximumRisk/1000.0,1);
//--- calcuulate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
           {
            Print("Error in history!");
            break;
           }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL)
            continue;
         //---
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1)
         lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//--- return lot size
   if(lot<0.1) lot=0.1;
   return(lot);
Reason: