Download MetaTrader 5

cannot load custom indicator 'B' [4002]

To add comments, please log in or register
Create Forum topics and improve your rating!
Thomas Schwabhäuser
77
Thomas Schwabhäuser 2016.06.15 17:51 

I am working on an indicator A that is supposed to operate on the values computed by another indicator B. I have implemented B with 6 buffers 5 of which are plotted. B works great when I attach it to any chart. It takes 8 parameters. The first 3 parameters are as for a moving average and then it takes 5 colors for plotting the 5 buffers accordingly.

In order to let A access the values it needs to load B as a custom indicator callling the function iCustom() in A's OnInit(). I thought everything is allright but when loading A to my chart I receive runtime error 4002 which the docs describe by Wrong parameter in the inner call of the client terminal function. The call to iCustom() is 

Bhandle=iCustom(NULL,0,"B",InpPeriod,InpShift,InpMethod,InpColor1,InpColor2,InpColor3,InpColor4);

but whereever I search I always end up confirming that I am passing a parameter of the expected type. I am following many Exempels by using the values NULL and 0 for symbol and period. Of course, B.ex5 is present in my indicator directory. Could anybody tell me how to figure out which Parameter MT5 complains about?

Thanks in advance!

Thomas 

Alain Verleyen
Moderator
30742
Alain Verleyen 2016.06.15 19:03  

Check your parameters type and position.

Show the B parameters and the relevant A code (parameters declaration and error checking) if you need help.

Thomas Schwabhäuser
77
Thomas Schwabhäuser 2016.06.15 20:09  
Alain Verleyen:

Check your parameters type and position.

Show the B parameters and the relevant A code (parameters declaration and error checking) if you need help.

Like I said the parameter types match. B has these parameters:

input string         _1 = "B parameters";

input int            InpPeriod=20;   // Period

input int            InpShift=0;     // Shift

input ENUM_MA_METHOD InpMethod=MODE_SMA; // Method

input string         _2 = "Color settings";

input color          InpColor1 = clrYellow;

input color          InpColor2 = clrRed;

input color          InpColor3 = clrGreen;

input color          InpColor4 = clrOrange;

A calls

handle=iCustom(NULL,0,"B",ExtPeriod,ExtShift,ExtMethod,

        ExtColor1,ExtColor2,ExtColor3,ExtColor4);

in its OnInit() handler after setting the desired values of the variables

int ExtPeriod;

int ExtShift;

ENUM_MA_METHOD ExtMethod;

color ExtColor1;

color ExtColor2;

color ExtColor3;

color ExtColor4; 

which are declared on the global  scope of A (as is int handle).

Now it seems to me the error could only be due to the "complex" data type ENUM_MA_METHOD. I will try changing it to int tomorrow but this seems inconvenient to me. Enumerations were introduced to ensure that only valid values can be passed and I would like to use this feature.

  1. Does anybody know if this could be the reason for my error?
  2. If so, why can't I use the enumeration?

Alain Verleyen
Moderator
30742
Alain Verleyen 2016.06.16 08:51  
Thomas Schwabhäuser:

Like I said the parameter types match. B has these parameters:

input string         _1 = "B parameters";

input int            InpPeriod=20;   // Period

input int            InpShift=0;     // Shift

input ENUM_MA_METHOD InpMethod=MODE_SMA; // Method

input string         _2 = "Color settings";

input color          InpColor1 = clrYellow;

input color          InpColor2 = clrRed;

input color          InpColor3 = clrGreen;

input color          InpColor4 = clrOrange;

A calls

handle=iCustom(NULL,0,"B",ExtPeriod,ExtShift,ExtMethod,

        ExtColor1,ExtColor2,ExtColor3,ExtColor4);


No your parameters don't match. Why are you thinking you can remove the string parameters ?

handle=iCustom(NULL,0,"B","",ExtPeriod,ExtShift,ExtMethod,"",ExtColor1,ExtColor2,ExtColor3,ExtColor4);
Thomas Schwabhäuser
77
Thomas Schwabhäuser 2016.06.16 10:24  
Alain Verleyen:

No your parameters don't match. Why are you thinking you can remove the string parameters ?

Because they are not actual parameters but only categorising the actual parameters. Of course, MT5 does not know of this difference. 

I'm not even sure if I should be angry at myself for not having thought of the simple answer. I am rather happy that I received your help letting me make progress. Thank you so much! 

Alain Verleyen
Moderator
30742
Alain Verleyen 2016.06.16 13:27  
Thomas Schwabhäuser:

Because they are not actual parameters but only categorising the actual parameters. Of course, MT5 does not know of this difference. 

I'm not even sure if I should be angry at myself for not having thought of the simple answer. I am rather happy that I received your help letting me make progress. Thank you so much! 

We all have to learn. You are welcome.
To add comments, please log in or register