Get the list of all custom indicator parameters

 

Hello,
Im developing an EA that uses some custom indicators, wich I load with the iCustom function, like:

almaHandle = iCustom(_Symbol, PERIOD_CURRENT,"name"); 

Now, I have the problem that although I of course know what are the parameters of those indicators,
becuase I can see them in the config window of the indicator when I pu it on a chart,
instead I don't know the order and the exact type of them, in order to pas them to the iCustom function, to 
load the indicator with values for the parameters different from the default ones.

To get the exact list of the indicators parameters I tried to use the "IndicatorParameters" function,
passing it the handle of the indicator, like here:

MqlParam defParams[];
const int p = IndicatorParameters(macd2Handle, itype, defParams);
Print("# ALMA PARAMETERS");
ArrayPrint(defParams);


but it doesn't work because the defParams array results empty...

So, I would like to know if there is some  other way to get the parameter list of a custom indicator...

Thanks!

 

I don't know if it is a typographical error in your post, or it is an error in your original code, but it seems incorrect because you are using different variables for the handle...

almaHandle = iCustom(_Symbol, PERIOD_CURRENT,"name"); 
const int p = IndicatorParameters(macd2Handle, itype, defParams);

Also, why are you declaring "p" as a "const"? That will make the variable unable to update at runtime.

You should only use "const" for initialising variables with a constant value for its entire lifetime, just as the term states. Don't use it for variables that get updated during runtime.

EDIT: Print and show your log output, including the "p" value and the enumeration value of "itype".

 
Fernando Carreiro #:

I don't know if it is a typographical error in your post, or it is an error in your original code, but it seems incorrect because you are using different variables for the handle...

Also, why are you declaring "p" as a "const"? That will make the variable unable to update at runtime.

You should only use "const" for initialising variables with a constant value for its entire lifetime, just as the term states. Don't use it for variables that get updated during runtime.

EDIT: Print and show your log output, including the "p" value and the enumeration value of "itype".

Hi Fernando, thanks for you reply.
Yes, sorry, I entered the code incorrectly in the message, but in the original code of the EA it is correct, that is:

 string name1 = "Examples\\alma_v2.ex5";
   almaHandle = iCustom(_Symbol, PERIOD_CURRENT, name1);

 MqlParam defParams[];
   int p = IndicatorParameters(almaHandle, itype, defParams); 
   Print("# ALMA PARAMETERS");
   ArrayPrint(defParams);

(now I omitted the "const" as you suggested). The problem is that,debugging, the array "defParams" appears to be empty,

and so the EA doesn't print anything. So I cannot understand where the problem could be...

 
A Atzori #: Yes, sorry, I entered the code incorrectly in the message, but in the original code of the EA it is correct, that is: (now I omitted the "const" as you suggested). The problem is that,debugging, the array "defParams" appears to be empty, and so the EA doesn't print anything. So I cannot understand where the problem could be...

If you want us to test your code, you should provide a small but complete sample source code (no executables), that can be tested by others to replicate your conditions.

For example, here is mine with log output, using the "Standard Examples" Alligator custom indicator ...

void OnStart() {
   string sIndicatorName   = "Examples\\Alligator";
   int    hIndicatorHandle = iCustom( _Symbol, PERIOD_CURRENT, sIndicatorName );
   if( hIndicatorHandle != INVALID_HANDLE ) {
      MqlParam       oParameters[];
      ENUM_INDICATOR eIndicatorType; 
      int            nParameterCount = IndicatorParameters( hIndicatorHandle, eIndicatorType, oParameters );
      PrintFormat( "Parameter count: %d, Indicator type: %s", nParameterCount, EnumToString( eIndicatorType ) );
      if( nParameterCount > 0 ) ArrayPrint( oParameters );
      IndicatorRelease( hIndicatorHandle );
   };
};
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    Parameter count: 9, Indicator type: IND_CUSTOM
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)        [type] [integer_value] [double_value]                  [string_value]
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [0]     14               0        0.00000 "Indicators\Examples\Alligator"
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [1]      7              13        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [2]      7               8        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [3]      7               8        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [4]      7               5        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [5]      7               5        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [6]      7               3        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [7]      7               2        0.00000 null                           
2024.12.01 13:47:58.768    TestParams (EURUSD,H1)    [8]      7               5        0.00000 null   
As you can see, it worked just fine, so use it as a reference for your own code.                       
 
Fernando Carreiro #:
void OnStart() {    string sIndicatorName   = "Examples\\Alligator";    int    hIndicatorHandle = iCustom( _Symbol, PERIOD_CURRENT, sIndicatorName );    if( hIndicatorHandle != INVALID_HANDLE ) {       MqlParam       oParameters[];       ENUM_INDICATOR eIndicatorType;       int            nParameterCount = IndicatorParameters( hIndicatorHandle, eIndicatorType, oParameters );       PrintFormat( "Parameter count: %d, Indicator type: %s", nParameterCount, EnumToString( eIndicatorType ) );       if( nParameterCount > 0 ) ArrayPrint( oParameters );       IndicatorRelease( hIndicatorHandle );    }; };

Ok Fernando, I understand...

Next time I will put all the necessary code to make the readers understand the problem.


Thanks to your code, however, I finally managed to make "IndicatorParameters" work.

Thanks for your precious help!