Bug found with input group and iCustom()

 

I recently raised the following issue, where I was having problems using input variables in a common file (MT5 V5.00 build 4150).

I eventually got to the bottom of the issue and believe that I have found a bug with input group when used with iCustom().

The input data is shown here...

enum LogLevel
{
   Error,
   Warn,
   Info
};

input group     "Debugging Options"
input LogLevel  Logging_Level = Warn;

The problem is that when you specify an input group, you also have to pass this as a parameter to iCustom() when passing in the input variable as a parameter.

If I remove the input group then it works as expected. I have checked the documentation and I can't see anything specific relating to the use of input group with an indicator.

Note: This only affects indicators and not expert advisors!

Should this be reported to the Service Desk. Looking around, it looks like the only place to report bugs now is here on the Forum?

Using inputs defined in common file
Using inputs defined in common file
  • 2024.01.23
  • www.mql5.com
I have created a logging file, called logging.mqh. Along with the class logic, I have also added the following code...
 
metaRaider: I recently raised the following issue, where I was having problems using input variables in a common file (MT5 V5.00 build 4150).

Have you updated to build 4153?

Is the issue still present on 4153?

 
Fernando Carreiro #:

Have you updated to build 4153?

Is the issue still present on 4153?

Just updated, and yes it is still an issue.

 
metaRaider #: Just updated, and yes it is still an issue.

Can you please create a working sample code for a indicator and an EA calling it, to replicate the issue, with log output to demonstrate it?

I will then do the same as a confirmation and after that, a comment can be posted the Russian thread and linked here to this topic for the developers to see and act on it.

 
Fernando Carreiro #:

Can you please create a working sample code for a indicator and an EA calling it, to replicate the issue, with log output to demonstrate it?

I will then do the same as a confirmation and after that, a comment can be posted the Russian thread and linked here to this topic for the developers to see and act on it.

Logging.mqh

enum LogLevel
{
   Error,
   Warn,
   Info
};

//+------------------------------------------------------------------+
//| P R O G R A M   I N P U T   P A R A M E T E R S                  |
//+------------------------------------------------------------------+
input group     "Debugging Options"
input LogLevel  Logging_Level = Warn;
input group     "Debugging Options 2"
input LogLevel  Logging_Level_2 = Warn;

Indicator.mq5

#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0

#include "Logging.mqh"

int OnInit()
{
        PrintFormat("Indicator Log Level: %s", EnumToString(Logging_Level));
        PrintFormat("Indicator Log Level 2: %s", EnumToString(Logging_Level_2));
        
        return (GetLastError());
}

void OnDeinit(const int reason)
{
}

int OnCalculate (const int rates_total,      // size of price[] array
                 const int prev_calculated,  // number of bars, calculated at previous call
                 const int begin,            // data begin index
                 const double& price[])      // array for calculation
{
        return (rates_total);
}

EA.mq5

#include "Logging.mqh"

int OnInit()
{
        PrintFormat("EA Log Level: %s", EnumToString(Logging_Level));
        PrintFormat("EA Log Level 2: %s", EnumToString(Logging_Level_2));

        if (iCustom(_Symbol, PERIOD_M1, "Indicator", "", Logging_Level, Logging_Level_2) == INVALID_HANDLE)
        {
                Print("Failed to load indicator");
        }
        
        return (GetLastError());
}

void OnDeinit(const int reason) {}

The running parameters are set to...

Example input parameters

The output is...

2024.01.24 11:38:16.878 EA (EURCHF,H1)  EA Log Level: Error
2024.01.24 11:38:16.878 EA (EURCHF,H1)  EA Log Level 2: Info
2024.01.24 11:38:16.898 Indicator (EURCHF,M1)   Indicator Log Level: Error
2024.01.24 11:38:16.898 Indicator (EURCHF,M1)   Indicator Log Level 2: Warn

Note: I added a blank group parameter for the 1st input parameter, which is why it is correct, but I haven't for the 2nd parameter, which is why it has defaulted to the default value and not the correct one (this...Indicator Log Level 2: Warn...should be...Indicator Log Level 2: Info).

 
metaRaider #:

Logging.mqh

Indicator.mq5

EA.mq5

The running parameters are set to...

The output is...

Note: I added a blank group parameter for the 1st input parameter, which is why it is correct, but I haven't for the 2nd parameter, which is why it has defaulted to the default value and not the correct one (this...Indicator Log Level 2: Warn...should be...Indicator Log Level 2: Info).

Please simplify it to the bare minimum, with no includes and no enumerations, using a simple data-types for inputs, like "int" or "double".

See if that still causes an issue, to make sure it is the "group" and not something else.

 
Fernando Carreiro #:

Please simplify it to the bare minimum, with no includes and no enumerations, using a simple data-types for inputs, like "int" or "double".

See if that still causes an issue, to make sure it is the "group" and not something else.

I did the following...

  1. I deleted the include file.
  2. Moved the inputs to the EA and Indicator.
  3. Changed the inputs to be ints.

When I delete the groups it works as expected, otherwise I still have the same issue.

 

Here is my own rendition and testing ...

Simple indicator:

#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0

input int      i_nNumber = 99;
input double   i_dbValue = 99.5;

int OnInit() {
   PrintFormat( "%s (%d,%.2f)", __FILE__, i_nNumber, i_dbValue );
   return INIT_SUCCEEDED;
};

int OnCalculate( const int rates_total, const int prev_calculated, const int begin, const double& price[] ) {
   return rates_total;
};

Group Indicator:

#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0

input group    "Group 1"
input int      i_nNumber = 99;
input group    "Group 2"
input double   i_dbValue = 99.5;

int OnInit() {
   PrintFormat( "%s (%d,%.2f)", __FILE__, i_nNumber, i_dbValue );
   return INIT_SUCCEEDED;
};

int OnCalculate( const int rates_total, const int prev_calculated, const int begin, const double& price[] ) {
   return rates_total;
};

Testing EA with various combinations ...

int hIndicatorSimple = INVALID_HANDLE,
    hIndicatorGroup1 = INVALID_HANDLE,
    hIndicatorGroup2 = INVALID_HANDLE,
    hIndicatorGroup3 = INVALID_HANDLE,
    hIndicatorGroup4 = INVALID_HANDLE;

int OnInit() {
   ResetLastError(); hIndicatorSimple = iCustom( _Symbol, _Period, "Indicator_simple",     0,     0.5 ); int errSimple = _LastError;
   ResetLastError(); hIndicatorGroup1 = iCustom( _Symbol, _Period, "Indicator_group",      1,     1.5 ); int errGroup1 = _LastError;
   ResetLastError(); hIndicatorGroup2 = iCustom( _Symbol, _Period, "Indicator_group",      2, "", 2.5 ); int errGroup2 = _LastError;
   ResetLastError(); hIndicatorGroup3 = iCustom( _Symbol, _Period, "Indicator_group",  "", 3,     3.5 ); int errGroup3 = _LastError;
   ResetLastError(); hIndicatorGroup4 = iCustom( _Symbol, _Period, "Indicator_group",  "", 4, "", 4.5 ); int errGroup4 = _LastError;
   PrintFormat( "Simple: %d (%d), Group1: %d (%d), Group2: %d (%d), Group3: %d (%d), Group4: %d (%d)",
      hIndicatorSimple, errSimple,
      hIndicatorGroup1, errGroup1, 
      hIndicatorGroup2, errGroup2,
      hIndicatorGroup3, errGroup3,
      hIndicatorGroup4, errGroup4 );
   return INIT_SUCCEEDED;
};

void OnDeinit( const int reason ) {
   IndicatorRelease( hIndicatorSimple );      
   IndicatorRelease( hIndicatorGroup1 );
   IndicatorRelease( hIndicatorGroup2 );
   IndicatorRelease( hIndicatorGroup3 );
   IndicatorRelease( hIndicatorGroup4 );
};

void OnTick() {
   ExpertRemove();
};

And the results from the Experts log ...

2024.01.24 13:10:46.512 expert_group (EURUSD,H1)        cannot load custom indicator 'Indicator_group' [4002]
2024.01.24 13:10:46.512 expert_group (EURUSD,H1)        Simple: 10 (0), Group1: 11 (0), Group2: -1 (4002), Group3: 12 (0), Group4: 13 (0)
2024.01.24 13:10:46.516 indicator_group (EURUSD,H1)     indicator_group.mq5 (4,4.50)
2024.01.24 13:10:46.518 indicator_group (EURUSD,H1)     indicator_group.mq5 (3,99.50)
2024.01.24 13:10:46.520 indicator_group (EURUSD,H1)     indicator_group.mq5 (1,99.50)
2024.01.24 13:10:46.522 indicator_simple (EURUSD,H1)    indicator_simple.mq5 (0,0.50)
2024.01.24 13:10:46.637 expert_group (EURUSD,H1)        ExpertRemove() function called

Conclusion ...

The Input Groups have to be included in the call to iCustom() function for it to work correctly, contrary to what the documentation may imply.

I would classify this as a bug, but given the propensity for MetaQuotes to deny certain bugs, they will most probably not fix it and classify it an oversight in the documentation.


Sample files have been attached ...

 
Fernando Carreiro #:

Here is my own rendition and testing ...

Simple indicator:

Group Indicator:

Testing EA with various combinations ...


And the results from the Experts log ...

Conclusion ...

The Input Groups have to be included in the call to iCustom() function for it to work correctly, contrary to what the documentation may imply.

I would classify this as a bug, but given the propensity for MetaQuotes to deny certain bugs, they will most probably not fix it and classify it an oversight in the documentation.


Sample files have been attached ...

Thanks for confirming.

I'll add a note in the code, because if they ever do fix it, it will break the current 'hacked' code.

 
metaRaider #: Thanks for confirming. I'll add a note in the code, because if they ever do fix it, it will break the current 'hacked' code.

I will report it in the Russian topics, but I don't know if they will do anything about it.

 

I have reported it ... https://www.mql5.com/ru/forum/1111/page3459#comment_51892293

Feel free to add your own comments there.

Ошибки, баги, вопросы
Ошибки, баги, вопросы
  • 2024.01.24
  • www.mql5.com
Общее обсуждение: Ошибки, баги, вопросы
Reason: