Optimization with "OnInit returned non-zero code 1:" error

Sunfire  

Hi all,


I ran optimization with MQL5 cloud network and I got this error: OnInit returned non-zero code 1. Can someone help me?

Full log at:

2020.06.19 20:36:33.874 Tester Experts indicator and trend 23.ex5 on EURUSD,M5 from 2020.06.15 00:00 to 2020.06.19 00:00

2020.06.19 20:36:33.874 Tester complete optimization started

2020.06.19 20:36:33.874 MQL5 Cloud Europe connecting to agent1.mql5.net:443

2020.06.19 20:36:33.875 MQL5 Cloud USA connecting to agent2.mql5.net:443

2020.06.19 20:36:34.330 MQL5 Cloud USA connected

2020.06.19 20:36:34.638 MQL5 Cloud Europe connected

2020.06.19 20:36:34.946 MQL5 Cloud USA authorized (server build 2490)

2020.06.19 20:36:35.871 MQL5 Cloud Europe authorized (server build 2490)

2020.06.19 20:36:36.483 MQL5 Cloud USA common synchronization completed

2020.06.19 20:36:38.937 MQL5 Cloud Europe common synchronization completed

2020.06.19 20:36:41.704 MQL5 Cloud USA pass 3310 tested with error "OnInit returned non-zero code 1" in 0:00:00.361 (PR 115)

2020.06.19 20:36:41.704 MQL5 Cloud USA pass 3312 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:41.704 MQL5 Cloud USA pass 3314 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:41.740 MQL5 Cloud USA pass 3316 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:42.010 MQL5 Cloud USA pass 3317 tested with error "OnInit returned non-zero code 1" in 0:00:00.009 (PR 115)

2020.06.19 20:36:42.011 MQL5 Cloud USA pass 3318 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.011 MQL5 Cloud USA pass 3319 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:42.317 MQL5 Cloud USA pass 3320 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.317 MQL5 Cloud USA pass 3321 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:42.317 MQL5 Cloud USA pass 3323 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.317 MQL5 Cloud USA pass 3324 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.317 MQL5 Cloud USA pass 3311 tested with error "OnInit returned non-zero code 1" in 0:00:00.372 (PR 101)

2020.06.19 20:36:42.318 MQL5 Cloud USA pass 3325 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3326 tested with error "OnInit returned non-zero code 1" in 0:00:00.009 (PR 101)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3327 tested with error "OnInit returned non-zero code 1" in 0:00:00.013 (PR 115)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3329 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3331 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3332 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3334 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3336 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.624 MQL5 Cloud USA pass 3338 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:42.741 MQL5 Cloud USA pass 3340 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.741 MQL5 Cloud USA pass 3341 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.751 MQL5 Cloud USA pass 3342 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.766 MQL5 Cloud USA pass 3343 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.794 MQL5 Cloud USA pass 3322 tested with error "OnInit returned non-zero code 1" in 0:00:00.315 (PR 134)

2020.06.19 20:36:42.827 MQL5 Cloud USA pass 3344 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.932 MQL5 Cloud USA pass 3345 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:42.932 MQL5 Cloud USA pass 3346 tested with error "OnInit returned non-zero code 1" in 0:00:00.005 (PR 134)

2020.06.19 20:36:42.933 MQL5 Cloud USA pass 3347 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:42.933 MQL5 Cloud USA pass 3348 tested with error "OnInit returned non-zero code 1" in 0:00:00.008 (PR 115)

2020.06.19 20:36:43.243 MQL5 Cloud USA pass 3349 tested with error "OnInit returned non-zero code 1" in 0:00:00.010 (PR 134)

2020.06.19 20:36:43.243 MQL5 Cloud USA pass 3350 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3351 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3352 tested with error "OnInit returned non-zero code 1" in 0:00:00.011 (PR 134)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3353 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3354 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3356 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3355 tested with error "OnInit returned non-zero code 1" in 0:00:00.011 (PR 134)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3357 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3360 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3358 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.546 MQL5 Cloud USA pass 3359 tested with error "OnInit returned non-zero code 1" in 0:00:00.011 (PR 134)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3361 tested with error "OnInit returned non-zero code 1" in 0:00:00.008 (PR 101)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3363 tested with error "OnInit returned non-zero code 1" in 0:00:00.010 (PR 134)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3362 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3364 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3366 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3365 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 134)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3367 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3369 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3368 tested with error "OnInit returned non-zero code 1" in 0:00:00.011 (PR 134)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3371 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.547 MQL5 Cloud USA pass 3372 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.549 MQL5 Cloud USA pass 3373 tested with error "OnInit returned non-zero code 1" in 0:00:00.011 (PR 134)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3374 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3375 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3376 tested with error "OnInit returned non-zero code 1" in 0:00:00.010 (PR 134)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3377 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3378 tested with error "OnInit returned non-zero code 1" in 0:00:00.009 (PR 115)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3379 tested with error "OnInit returned non-zero code 1" in 0:00:00.008 (PR 134)

2020.06.19 20:36:43.744 MQL5 Cloud USA pass 3382 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.749 MQL5 Cloud USA pass 3383 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:43.854 MQL5 Cloud USA pass 3384 tested with error "OnInit returned non-zero code 1" in 0:00:00.011 (PR 134)

2020.06.19 20:36:43.854 MQL5 Cloud USA pass 3385 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:43.854 MQL5 Cloud USA pass 3386 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.161 MQL5 Cloud USA pass 3387 tested with error "OnInit returned non-zero code 1" in 0:00:00.012 (PR 134)

2020.06.19 20:36:44.161 MQL5 Cloud USA pass 3388 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3389 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3390 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 134)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3391 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3392 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3395 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3394 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3393 tested with error "OnInit returned non-zero code 1" in 0:00:00.004 (PR 134)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3397 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 115)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3398 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3399 tested with error "OnInit returned non-zero code 1" in 0:00:00.005 (PR 134)

2020.06.19 20:36:44.163 MQL5 Cloud USA pass 3370 tested with error "OnInit returned non-zero code 1" in 0:00:00.343 (PR 143)

2020.06.19 20:36:44.470 MQL5 Cloud USA pass 3402 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.470 MQL5 Cloud USA pass 3403 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.470 MQL5 Cloud USA pass 3404 tested with error "OnInit returned non-zero code 1" in 0:00:00.005 (PR 134)

2020.06.19 20:36:44.470 MQL5 Cloud USA pass 3406 tested with error "OnInit returned non-zero code 1" in 0:00:00.005 (PR 143)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3407 tested with error "OnInit returned non-zero code 1" in 0:00:00.009 (PR 115)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3408 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3409 tested with error "OnInit returned non-zero code 1" in 0:00:00.004 (PR 134)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3411 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3412 tested with error "OnInit returned non-zero code 1" in 0:00:00.008 (PR 101)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3414 tested with error "OnInit returned non-zero code 1" in 0:00:00.006 (PR 115)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3415 tested with error "OnInit returned non-zero code 1" in 0:00:00.007 (PR 101)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3413 tested with error "OnInit returned non-zero code 1" in 0:00:00.005 (PR 134)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3410 tested with error "OnInit returned non-zero code 1" in 0:00:00.004 (PR 143)

2020.06.19 20:36:44.471 MQL5 Cloud USA pass 3380 tested with error "OnInit returned non-zero code 1" in 0:00:00.292 (PR 144)

***** I clicked Stop ***************************


2020.06.19 20:36:44.526 Tester optimization finished, total passes 93 (successful 0 passes)

2020.06.19 20:36:44.526 Statistics optimization done in 0 minutes 11 seconds

2020.06.19 20:36:44.526 Statistics shortest pass 0:00:00.000, longest pass 0:00:00.000, average pass 0:00:00.000

2020.06.19 20:36:44.526 Statistics local 0 tasks (0%), remote 0 tasks (0%), cloud 93 tasks (100%)

2020.06.19 20:36:44.526 MQL5 Cloud Europe connection closed

2020.06.19 20:36:44.527 MQL5 Cloud USA connection closed

2020.06.19 20:36:44.527 Tester stopped by user



Distributed Computing in the MQL5 Cloud Network
Distributed Computing in the MQL5 Cloud Network
  • cloud.mql5.com
Today's computers spend most of their time idle and do not use all the features of their CPU. Now you can benefit from the spare power of your PC. You can sell your computer's CPU time to other members of our network community for a variety of tasks like optimizing Expert Advisors optimization or developing mathematical models. Join the MQL5...
Sunfire  
The code is not done by me, it is done by a freelance coder. He is the one asked me to post it here to ask for help.
William Roeder  
Irrevalent. We can't see his broken code. Only your coder knows why his OnInit is returning one (INIT_FAILED). Have him fix his broken code.
Sunfire  
William Roeder:
Irrevalent. We can't see his broken code. Only your coder knows why his OnInit is returning one (INIT_FAILED). Have him fix his broken code.
I think I have to mention that when I do optimization on local PC with multiple core, it does not have the error and it is able to complete. The error message happen when do optimization using MQL5 Cloud Network Agent.
Alain Verleyen  
firecard:
I think I have to mention that when I do optimization on local PC with multiple core, it does not have the error and it is able to complete. The error message happen when do optimization using MQL5 Cloud Network Agent.
It changes nothing. The answer is in the code. Post the relevant code (OnInit function) if you want help.
Sunfire  

Here is the code, appreciate any help:

//---===================== The OnInit function  =======================================================

int OnInit()

  {



   stoplevel = (int)(SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL) + SymbolInfoInteger(_Symbol,SYMBOL_SPREAD) + SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL));

   double LotStep = SymbolInfoDouble(Symbol(), SYMBOL_VOLUME_STEP);

   if(LotStep >= 1) LotDigits = 0;

   else if(LotStep >= 0.1) LotDigits = 1;

   else if(LotStep >= 0.01) LotDigits = 2;

   else LotDigits = 3;

   pipoffset = NormalizeDouble(Distance * Point(), Digits());   //initialize crossed

 for (int i = 0; i < ArraySize(crossed); i++)

   crossed[i] = true;



//

if(Main_Detection==Indicator_1)

{  

   hull_handle = iCustom(Symbol(), Period(),indi,inpSchaffPeriod,inpFastPeriod,inpSlowPeriod,inpSmoothPeriod,inpPrice);

   if(hull_handle==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the hull_handle indicator for the symbol %s/%s, error code %d",

                  EnumToString(Period()),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }

}

//

if(Main_Detection==Indicator_2)

{  

   cycle_handle = iCustom(Symbol(), Period(),indi2,SchaffPeriod,FastEma,SlowEma,SmoothPeriod,Price);

   if(cycle_handle==INVALID_HANDLE)

     {

      //--- tell about the failure and output the error code 

      PrintFormat("Failed to create handle of the cycle_handle indicator for the symbol %s/%s, error code %d",

                  EnumToString(Period()),

                  GetLastError());

      //--- the indicator is stopped early 

      return(INIT_FAILED);

     }

}

//

if(Use_ADX_Filter)

{

   adx_handle = iADX(NULL, PERIOD_CURRENT,ADX_Period);

   if(adx_handle < 0)

     {

      Print("The creation of adx_handle has failed: adx_handle=", INVALID_HANDLE);

      Print("Runtime error = ", GetLastError());

      return(INIT_FAILED);

     }

}

//

if(Use_MA_Filter)

{

   ma_handle = iMA(NULL,PERIOD_CURRENT,MA_Period,MA_Shift,MA_Method,MA_Price);

   if(ma_handle < 0)

     {

      Print("The creation of ma_handle has failed: ma_handle=", INVALID_HANDLE);

      Print("Runtime error = ", GetLastError());

      return(INIT_FAILED);

     }

   ma2_handle = iMA(NULL,PERIOD_CURRENT,MA2_Period,MA2_Shift,MA2_Method,MA2_Price);

   if(ma2_handle < 0)

     {

      Print("The creation of ma2_handle has failed: ma_handle=", INVALID_HANDLE);

      Print("Runtime error = ", GetLastError());

      return(INIT_FAILED);

     }

}

if(Use_Candle_Filter)

{

   candle_handle = iCustom(Symbol(),PERIOD_CURRENT,"Daily open line",TimeShift);

   if(candle_handle < 0)

     {

      Print("The creation of candle_handle has failed: candle_handle=", INVALID_HANDLE);

      Print("Runtime error = ", GetLastError());

      return(INIT_FAILED);

     }

}

   return(0);

  }

//---===================== The OnTick function ======================================================



William Roeder  
  1. firecard: Here is the code,

    Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. hull_handle = iCustom(Symbol(),Period(),indi,inpSchaffPeriod,inpFastPeriod,inpSlowPeriod,inpSmoothPeriod,inpPrice);
    
    cycle_handle = iCustom(Symbol(), Period(),indi2,SchaffPeriod,FastEma,SlowEma,SmoothPeriod,Price);  
    
    candle_handle = iCustom(Symbol(),PERIOD_CURRENT,"Daily open line",TimeShift);
    

    The three indicators aren't part of your product. Therefor product can't use them except when running on your machine. Why does this surprise you when you try to use the cloud or Market Validation?

    Just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
              Use the publicly released code - MQL5 programming forum 2017.02.20
              Resources - MQL4 Reference

    Be aware that using resources is 40x times slower than using CIs directly.
              A custom indicator as a resource - MQL4 programming forum 2019.11.26

  3.    stoplevel = (int)(SymbolInfoInteger(_Symbol,SYMBOL_TRADE_FREEZE_LEVEL) + SymbolInfoInteger(_Symbol,SYMBOL_SPREAD) + SymbolInfoInteger(_Symbol, SYMBOL_TRADE_STOPS_LEVEL));
    Don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Sunfire  
William Roeder:
  1. Just embed the other indicator(s) inside your indicator/EA. Add the CI(s) to your code as a resource.
              Use the publicly released code - MQL5 programming forum 2017.02.20
              Resources - MQL4 Reference

    Be aware that using resources is 40x times slower than using CIs directly.
              A custom indicator as a resource - MQL4 programming forum 2019.11.2


Thank you for the reply, my coder did do the embedded version, when I try to run optimization at using cloud agent, I get:

2020.06.20 21:34:55.480 Tester obsolete version of resource "Experts\job 120487 indicator and trend 24.ex5::Indicators\trend cycle - Hull.ex5" can be used on local or remote agents only, no Cloud
21:36
2020.06.20 21:34:55.480 Tester obsolete version of resource "Experts\job 120487 indicator and trend 24.ex5::Indicators\Trend Cycle.ex5" can be used on local or remote agents only, no Cloud