BUG: `iCustom` succeeds even though indicator `OnInit` exits with `INIT_PARAMETERS_INCORRECT`

To add comments, please log in or register
danielsokolowsk
70
danielsokolowsk  

Seriously MetaTrader !!!?! This is at least a 6 year old issues! 

As the subject states, iCustom should return -1 (INVALID_HANDLE) for an indicator that returns `INIT_PARAMETERS_INCORRECT` in it's `OnInit` function.

Does anyone have a strategy to detect a failed iCustom?
danielsokolowsk
70
danielsokolowsk  
Or more logically iCustom should return INIT_PARAMETERS_INCORRECT so one can detect that was the reason. 
Alain Verleyen
37992
Alain Verleyen  
danielsokolowsk:

Seriously MetaTrader !!!?! This is at least a 6 year old issues! 

As the subject states, iCustom should return -1 (INVALID_HANDLE) for an indicator that returns `INIT_PARAMETERS_INCORRECT` in it's `OnInit` function.

Does anyone have a strategy to detect a failed iCustom?

That's right, good luck to have it fixed.

I had a ticket about that open for years...now the Service Desk is closed for such things and all tickets were removed.

The only simple way is to check the parameters in the calling code, it's a pity but that's it. So actually the INIT_PARAMETERS_INCORRECT is just useless for such case.
danielsokolowsk
70
danielsokolowsk  

So god damn sad, MQL5 is a poor excuse for a language, so many gotchas, side-effects, and weirdness, like local testing agents will swallow any 'OnTick' alerts, making debugging that much harder....I do question my sanity of why I came back to trying to code in it. 

Anyone that cares here is the approach I ended up doing:


/*
* Expert initialization function
* ##############################
*/
int OnInit() {
        _fPrint(">>> " + __FILE__ + "." + __FUNCTION__ + "()");
        EventSetTimer(nON_TIMER_FREQUENCY_SECONDS); _fPrint("=== " + __FILE__ + "." + __FUNCTION__ + "(): set `nON_TIMER_FREQUENCY_SECONDS=" + nON_TIMER_FREQUENCY_SECONDS + "`");
        
        
        iENTRY_PATTERN_SIGNAL_HANDLE = iCustom(
                _Symbol
                , _Period 
                // relative paths stopped working,"..\\Experts\\DS2_1MilNetWorthBy40\\Indicators\\" + EnumToString(iENTRY_PATTERN_SIGNAL)
                ,EnumToString(iENTRY_PATTERN_SIGNAL)
                ,dENTRY_PATTERN_ARG1
                ,dENTRY_PATTERN_ARG2
                ,dENTRY_PATTERN_ARG3
                ,dENTRY_PATTERN_ARG4
                ,dENTRY_PATTERN_ARG5
                ,dENTRY_PATTERN_ARG6
        );

        if (INVALID_HANDLE == iENTRY_PATTERN_SIGNAL_HANDLE) {
                _fAlertAndErrorExit("===" + __FILE__ + "." + __FUNCTION__ + "(): CRITICAL: getting signal handle failed, `EnumToString(eENTRY_PATTERN_SIGNALS)=`"
                                + EnumToString(iENTRY_PATTERN_SIGNAL) + ", `_LastError=" + _LastError + "`"
                                + "`, `ErrorDescription(_LastError)=" + ErrorDescription(_LastError) + "`");                
        }
        // 2018-Oct-31: fucken stupid MetaTrader, even if indicator does `INIT_PARAMETERS_INCORRECT`, the handle is still valid!
        //                               see: https://www.mql5.com/en/forum/287291
        Sleep(1000); // needed
        int iTemp = BarsCalculated(iENTRY_PATTERN_SIGNAL_HANDLE);       
        if (BarsCalculated(iENTRY_PATTERN_SIGNAL_HANDLE) <= 0) {
                return(INIT_PARAMETERS_INCORRECT);              
        }
        _fPrint("<<< " + __FILE__ + "." + __FUNCTION__ + "(): `return(INIT_SUCCEEDED)=" + INIT_SUCCEEDED + "`");
   return(INIT_SUCCEEDED);
}
BUG: `iCustom` succeeds even though indicator `OnInit` exits with `INIT_PARAMETERS_INCORRECT`
BUG: `iCustom` succeeds even though indicator `OnInit` exits with `INIT_PARAMETERS_INCORRECT`
  • 2018.11.01
  • www.mql5.com
Seriously MetaTrader !!!?! This is at least a 6 year old issues...
Alain Verleyen
37992
Alain Verleyen  
danielsokolowsk:

So god damn sad, MQL5 is a poor excuse for a language, so many gotchas, side-effects, and weirdness, like local testing agents will swallow any 'OnTick' alerts, making debugging that much harder....I do question my sanity of why I came back to trying to code in it. 

Anyone that cares here is the approach I ended up doing:


Sleep() usage usually worst then the original problem in my opinion, but if you are satisfied with it just do it.

mql5 and MT5 are great tools to use, with some weaknesses and weird development practices from Metaquotes. I would not reject all due to these issues, which are certainly occurring on any trading platforms too. Just an opinion.

To add comments, please log in or register