Test on EURUSD,H1 (netting) tester stopped because OnInit returns non-zero code -1 disconnected there are no trading operations

 



While running an automatic market tester for verification, I encountered an error with my EA that is intended to only trade US330. As I understand that this might violate the market rules for EA limitations, I updated the OnInit function to alert the user instead of returning a non-zero error code for the specified symbol and time frame. However, I am still facing the same error when testing my EA with any other symbol. I suspect that I need to modify my EA to allow trading any symbol and timeframe, but I am not sure where the error is. Can anyone help me identify the mistake?


Error code: 

test on EURUSD,H1 (netting) tester stopped because OnInit returns non-zero code -1 disconnected there are no trading operations


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ExtTrade.SetExpertMagicNumber(MagicNumber);
   ExtTrade.SetMarginMode();
   ExtTrade.SetTypeFillingBySymbol(Symbol());
   symbol_Info.Name(Symbol());

//--- Check inputs
   double minlot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MIN);
   double maxlot = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_MAX);
   Print("Min Lot size: ", minlot," Max lot size: ",maxlot);

   if(Lots < minlot || Lots > maxlot)
     {
      Alert("Invalid Lot Size");
      return(-1);
     }

   if(MaxDailyDrawDown >= 0)
     {
      Alert("Max daily balance drawdown must be a negative number");
      return(-2);
     }
   if(MagicNumber <= 0)
     {
      Alert("Magic number must be a positive interger");
      return(0);
     }

   if(Period() != PERIOD_M4)
     {
      Alert("Invalid Time Frame, EA runs on the 4 minute chart!");
      return(0);
     }

   string US30Symbol= Symbol();
   Print("The current symbol is: ",US30Symbol);
   if(US30Symbol != "US30")
     {
      Alert("Invalid Symbol, EA exclusively trades US30");
      return(0);
     }


   double MyPoint=_Point;
   if(_Digits==3 || _Digits==5)
      MyPoint=_Point*10;
   PointValue= MyPoint;

   if(CheckActiveHours())

   WeekDays[0]=Sunday;
   WeekDays[1]=Monday;
   WeekDays[2]=Tuesday;
   WeekDays[3]=Wednesday;
   WeekDays[4]=Thursday;
   WeekDays[5]=Friday;
   WeekDays[6]=Saturday;

   Vigor_Handle = iRVI(_Symbol,PERIOD_CURRENT,VigorIndexPeriod);
   if(Vigor_Handle==INVALID_HANDLE)
     {
      printf("Error creating Vigor Index indicator");
      return(-6);
     }

   Force_Handle = iForce(_Symbol,PERIOD_CURRENT,Forceindexperiod, MODE_SMA,VOLUME_TICK);
   if(Force_Handle==INVALID_HANDLE)
     {
      printf("Error creating Force Index indicator");
      return(-7);
     }

//--- Moving Average indicator
   EMA1_Handle=iMA(_Symbol,_Period,MovingPeriod1,0,MODE_SMA,PRICE_CLOSE);
   if(EMA1_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-8);
     }

   EMA2_Handle=iMA(_Symbol,_Period,MovingPeriod2,0,MODE_SMA,PRICE_CLOSE);
   if(EMA2_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-9);
     }

   EMA3_Handle=iMA(_Symbol,_Period,MovingPeriod3,0,MODE_SMA,PRICE_CLOSE);
   if(EMA3_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-10);
     }

   EMA4_Handle=iMA(_Symbol,_Period,MovingPeriod4,0,MODE_SMA,PRICE_CLOSE);
   if(EMA4_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-11);
     }

   EMA5_Handle=iMA(_Symbol,_Period,MovingPeriod5,0,MODE_SMA,PRICE_CLOSE);
   if(EMA5_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-12);
     }

   EMA2Shift_Handle=iMA(_Symbol,_Period,MovingPeriod2,MovingPeriodShiftValue,MODE_SMA,PRICE_CLOSE);
   if(EMA2Shift_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-13);
     }

   EMA_TrailSL_Handle=iMA(_Symbol,_Period,MovingPeriodSL,0,MODE_SMA,PRICE_CLOSE);
   if(EMA_TrailSL_Handle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-14);
     }

//--- ok
   return(INIT_SUCCEEDED);
  }
 
Rafael Santos:



While running an automatic market tester for verification, I encountered an error with my EA that is intended to only trade US330. As I understand that this might violate the market rules for EA limitations, I updated the OnInit function to alert the user instead of returning a non-zero error code for the specified symbol and time frame. However, I am still facing the same error when testing my EA with any other symbol. I suspect that I need to modify my EA to allow trading any symbol and timeframe, but I am not sure where the error is. Can anyone help me identify the mistake?


Error code: 

test on EURUSD,H1 (netting) tester stopped because OnInit returns non-zero code -1 disconnected there are no trading operations


According to your code -1 means invalid lot size. You may modify the volume.
 
Yashar Seyyedin #:
According to your code -1 means invalid lot size. You may modify the volume.

Dear Yashar, thank you for your prompt response.

Regarding the lot size limitation, the code only restricts it based on the maximum and minimum allowed volume of the symbol, and it's not clear if this would be deemed as an EA limitation as this is typically broker-dependent. I have modified the code to return a value of 0, but I am still facing the same issue, where the EA only works with US30.


Thank you,

 
Rafael Santos #:

Dear Yashar, thank you for your prompt response.

Regarding the lot size limitation, the code only restricts it based on the maximum and minimum allowed volume of the symbol, and it's not clear if this would be deemed as an EA limitation as this is typically broker-dependent. I have modified the code to return a value of 0, but I am still facing the same issue, where the EA only works with US30.


Thank you,

Just wanted to emphasize that it works on US30 Live account and back test but I get the error when trading any other symbol.

 
Rafael Santos #:

Just wanted to emphasize that it works on US30 Live account and back test but I get the error when trading any other symbol.

What is the value of your variable Lots ? It's not in the posted code.

 
Alain Verleyen #:

What is the value of your variable Lots ? It's not in the posted code.

input int MagicNumber =112916;//Magic Number
input double Lots     = 1.0; // Lots
input double MaxDailyDrawDown = -2000.00; //Max daily balance drawdown

Hello Alain,

I am pleased to inform you that the issue with my EA has been resolved. As per the suggestion of Yashar, juts needed to rebooted my MT5 platform and the updates were successfully registered. I am now able to trade with my EA in all symbols and time frames.

Thank you for your assistance and support.

Best regards