Error 131 when trying to publish a simple EA to the market.

 
void OnTick()
  {
   Count();

   if (Automated==true){
   
   if(count1==0){
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   if(count2==0){
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   }
   
  }
//+------------------------------------------------------------------+
void Count()
{   
   count1=0;count2=0;profit=0;
   swap1=0;swap2=0;commission1=0;commission2=0;
   
   for (int i=OrdersTotal()-1; i>=0; i--){
      if (!OrderSelect(i, SELECT_BY_POS,MODE_TRADES))continue;
      if (OrderSymbol()!=Symbol())continue;
         profit = profit + OrderProfit();
         if (OrderType()==0){
            count1++;
            commission1=commission1+OrderCommission();
            swap1=swap1+OrderSwap();
         }
         if (OrderType()==1){
            count2++;
            commission2=commission2+OrderCommission();
            swap2=swap2+OrderSwap();
         }
   }
} 

I have tried to research similar issue in the forum, and tested a few of them without success. Appreciate if someone can pointed out what is the problem. Code is attached. 

 
Tan Chee Ho:

I have tried to research similar issue in the forum, and tested a few of them without success. Appreciate if someone can pointed out what is the problem. Code is attached. 

Minumum Lots size error.Minimum lots of GBPCHF symbol. The amount is too small.

void OnTick()
  {
   double Lots=0.01;
   Count();
   double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
   if(Lots<MinLots) Alert("Lots Size Error for Minumum Lots Size");ExpertRemove();
   if (Automated==true){
   
   if(count1==0){
   int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   if(count2==0){
   int ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   }
   
  }
 
Mehmet Bastem:

Minumum Lots size error.Minimum lots of GBPCHF symbol. The amount is too small.

Thank you very much for taking time to reply my message. Appreciate your reply. 

 
void OnTick()
  {
   double Lots=0.01;
   
   Count();
   double MinLots=MarketInfo(Symbol(),MODE_MINLOT);
   if(Lots<MinLots) 
   Print("Lots Size Error for Minumum Lots Size");
   ExpertRemove();
   
   if (Automated==true){
   
   if(count1==0){
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   if(count2==0){
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   }
   
  }

I have tried to follow your advice, and I changed the "Alert" to "Print". When I try to upload it to the market, it appear to have less error now. But it has the same error 131 on "NZDUSD".

Is there something I need to be aware of?


 

I try to change the lotsize from 0.01 to 1.00, and the following error came. which is the same as the first time. 


 
Tan Chee Ho: I have tried to research similar issue in the forum, and tested a few of them without success. Appreciate if someone can pointed out what is the problem. Code is attached. 

You have to adjust your volume size based on the the Lot Step and check for both Maximum and Minimum amounts. Here is an example from another thread (pay special attention to beginning and end of the code below):

Forum on trading, automated trading systems and testing trading strategies

How to calculate lots using multiplier according to number of opened orders?

Fernando Carreiro, 2017.09.01 21:57

Don't use NormalizeDouble(). Here is some guidance (code is untested, just serves as example):

// Variables for Symbol Volume Conditions
double
   dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
   dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
   dblLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );
   
// Variables for Geometric Progression
double
   dblGeoRatio = 2.8,
   dblGeoInit  = dblLotsMinimum;
   
// Calculate Next Geometric Element
double
   dblGeoNext  = dblGeoInit * pow( dblGeoRatio, intOrderCount + 1 );
   
// Adjust Volume for allowable conditions
double
   dblLotsNext = fmin( dblLotsMaximum,                                     // Prevent too greater volume
                   fmax( dblLotsMinimum,                                   // Prevent too smaller volume
                     round( dblGeoNext / dblLotsStep ) * dblLotsStep ) );  // Align to Step value

 
Fernando Carreiro:

You have to adjust your volume size based on the the Lot Step and check for both Maximum and Minimum amounts. Here is an example from another thread (pay special attention to beginning and end of the code below):


Thank you, will try to modify my code and try again. Appreciate!

 
void OnTick()
  {
   double Lots=0.1;
   
   Count();
   // Variables for Symbol Volume Conditions
   double
      dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
      dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
      dblLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );
      
   // Adjust Volume for allowable conditions
   double
      dblLotsNext = fmin( dblLotsMaximum,                                     // Prevent too greater volume
                      fmax( dblLotsMinimum,                                   // Prevent too smaller volume
                        round( Lots / dblLotsStep ) * dblLotsStep ) );  // Align to Step value   
   
   if(Lots<dblLotsNext){ 
   Print("Lots Size Error for Minumum Lots Size");
   //ExpertRemove();
   Lots=dblLotsMinimum;
   }
   if (Automated==true){
   
   if(count1==0){
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   if(count2==0){
   int ticket=OrderSend(Symbol(),OP_BUY,0.01,Ask,3,0,0,"My order",0,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 
   }
   }
   
  }

I have updated to the suggested code above, and Instead of remove EA function, I have choose if the lots size is smaller than the minimum, choose the minimum to open trade. But the same error appeared. 

 

The version of MetaEditor I am using is as the image below. Could that be an issue? Or could that error is not about the code???


 
Tan Chee Ho: I have updated to the suggested code above, and Instead of remove EA function, I have choose if the lots size is smaller than the minimum, choose the minimum to open trade. But the same error appeared. 

What is the use of copy/pasting my code and then not actually using it in your OrderSend()? Do it properly!

void OnTick()
{
   double Lots=0.1;

   Count();

   // Variables for Symbol Volume Conditions
   double
      dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
      dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
      dblLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );

   // Adjust Volume for allowable conditions
   double
      dblLots = fmin( dblLotsMaximum,                                // Prevent too greater volume
                  fmax( dblLotsMinimum,                              // Prevent too smaller volume
                     round( Lots / dblLotsStep ) * dblLotsStep ) );  // Align to Step value

   if (Automated==true)
   {
      if(count1==0)
      {
         int ticket=OrderSend(Symbol(), OP_BUY, dblLots, Ask, 3, 0, 0, "My order", 0, 0, clrGreen);
         if(ticket<0)
            Print("OrderSend failed with error #", GetLastError());
         else
            Print("OrderSend placed successfully");
      }
      if(count2==0)
      {
         int ticket=OrderSend(Symbol(), OP_BUY, dblLots, Ask, 3, 0, 0, "My order", 0, 0, clrGreen);
         if(ticket<0)
            Print("OrderSend failed with error #", GetLastError());
         else
            Print("OrderSend placed successfully");
      }
   }
}
 
Fernando Carreiro:

What is the use of copy/pasting my code and then not actually using it in your OrderSend()? Do it properly!

Sincerely apologize for overlooked the code below it. Thanks for reminding.  

Reason: