test on EURUSD,H1 (hedging) tester stopped because OnInit returns non-zero code 1 disconnected

 

Dear colleagues, When running the automated validation tool to publish my EA, I get the following error. test on EURUSD,H1 (hedging) tester stopped because OnInit returns non-zero code 1 disconnected

//+------------------------------------------------------------------+
int OnInit(){
   if(_Period != PERIOD_D1)    {
      Print(__FUNCTION__,"Initiation failed. This expert advisor must be run on the daily chart.");
      return(INIT_FAILED);
   }
   if(!CheckInputs()) return(INIT_FAILED);
   Trade.SetExpertMagicNumber(MagicNumber);
   BarsTotal = iBars(_Symbol,PERIOD_CURRENT);
   handle_BB  = iBands(_Symbol,PERIOD_CURRENT,20,0,2,PRICE_CLOSE);
   return(INIT_SUCCEEDED);
}

Does anyone have a solution for this?

With kind regards

Johan

Improperly formatted code edited by moderator. Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
You forced the EA to run only on daily timeframe and not initialize otherwise.

The tester try different timeframes, as you can see you got the error because it's testing H1.

I strongely suggest to hardcode timeframes you need instead of using PERIOD_CURRENT making restrictions on the chart you need to run it. 
 
Fabio Cavalloni #:
You forced the EA to run only on daily timeframe and not initialize otherwise.

The tester try different timeframes, as you can see you got the error because it's testing H1.

I strongely suggest to hardcode timeframes you need instead of using PERIOD_CURRENT making restrictions on the chart you need to run it. 

Hi Fabio,

Thank you for your suggestion. Unfortunately, it doesn't solve the problem. I even added a few code lines in the OnTick, to test if the timeframe equals PERIOD_D1. That didn't help either.

And something I don't get, if I explicitly state in the Oninit that I only need PERIOD_D1, the automated validation should respect that, and stop right there if that is not the case.

Anyway, to be continued :-)

Kind regards,

Johan

 
Wrong consideration... You can't restrict the tester to your wanted scenario and pass the validation.

Remove all your timeframe restrictions and checks and code PERIOD_D1 instead of PERIOD_CURRENT where you need it.
 
Fabio Cavalloni #:
Wrong consideration... You can't restrict the tester to your wanted scenario and pass the validation.

Remove all your timeframe restrictions and checks and code PERIOD_D1 instead of PERIOD_CURRENT where you need it.

Thanks for the support Fabio.

I replaced the PERIOD_CURRENT with PERIOD_D1 and deleted the first if - statement from the OnInit() function.

I ended up with another set of errors, which I could solve in several iterations.

With kind regards,

Johan