I just want to get some value from Indicator "ZigZag" by iCustom(), but always fail

 

My EA code is as below:



int i_0=0,i_1=0,i_2=0;
double x[50],y[50],z[50];

int init()
  {     
 ArrayInitialize(x,0.0);
 ArrayInitialize(y,0.0);
 ArrayInitialize(z,0.0);
   return(0);
  }
  
int deinit()
  {
   return(0);
  }

int start()
  {
int i=100;
while(i<100)
{
  if(iCustom(NULL,0,"Test_Ind",12,5,3,1,i_0)!=0){ x[i_0]=iCustom(NULL,0,"Test_Ind",12,5,3,1,i_0);i_0++;}
  if(iCustom(NULL,0,"Test_Ind",12,5,3,2,i_1)!=0){ x[i_1]=iCustom(NULL,0,"Test_Ind",12,5,3,1,i_1);i_1++;}
  if(iCustom(NULL,0,"Test_Ind",12,5,3,0,i_2)!=0){ x[i_2]=iCustom(NULL,0,"Test_Ind",12,5,3,1,i_2);i_2++;}
  i++;
}
while(i>90)
{
if(x[100-i]!=0||y[100-i]!=0||z[100-i]!=0)
Print("x,y,z: ",x[100-i]," , ",y[100-i]," , ",z[100-i]);
i--;
}


   return(0);
  }
  

When I test it on history data and live data, iCustom() returns all 0; I don;t know why?

 

vx0532:

I just want to get some value from Indicator "ZigZag" by iCustom(), but always fail

My EA code is as below: When I test it on history data and live data, iCustom() returns all 0; I don;t know why?

Examples here https://www.mql5.com/en/forum/144092.

 
You don't call the zigzag indicator. ???
 
GumRai:
You don't call the zigzag indicator. ???


sorry, In the fact, I copy codes of zigzag to test_Ind.

I have know the matter after view the post which is suggested by "buzen ".

I think the key point is that:

in Indicator, we can set array to receive the value returned by iCustom(); and In EA, we can't use array but variable to receive the value returned by iCustom(), since in EA if we use array x[i] to receive the return value, " buffers and you have to find value of i at what bar the top or bottom will be" said be by deVries at https://www.mql5.com/en/forum/144092/page2.

So I think iCustom not simply return one value but other somethings which can recognize what receive it.

 
vx0532:


So I think iCustom not simply return one value but other somethings which can recognize what receive it.

iCustom() returns a single double, not an array or anything else, if fact a function cannot return an array . . . please read the documentation: iCustom()
 
RaptorUK:
iCustom() returns a single double, not an array or anything else, if fact a function cannot return an array . . . please read the documentation: iCustom()


if that, MT4 platform must take the responsibility to recognize iCustom() be used in EA or Indicator.
 
vx0532:

if that, MT4 platform must take the responsibility to recognize iCustom() be used in EA or Indicator.
No . . .
 
  1. int i=100;
    while(i<100) // i==100 loop exits iCustom is NEVER called
  2. while(i<100)
    {
      if(iCustom(NULL,0,"Test_Ind",12,5,3,1,i_0)!=0){ x[i_0]=iCustom(NULL,0,"Test_Ind",12,5,3,1,i_0);i_0++;}
    What is the purpose of i when you don't use it in the loop?
  3. Where are you resetting i_0 ...
 
WHRoeder:
  1. What is the purpose of i when you don't use it in the loop?
  2. Where are you resetting i_0 ...


sorry, int i=100; should be int i=0; now it is ok; and in EA array also can receive iCustom()'s return.

Thanks.

Now I know. In the fact the arrays, like x[], only can be used in Indicator not in EA;

iCustom()'s return value can be received by both double variable and double array, both in EA and Indicator; but if its return value should be received by double array, in EA the array should be the type "double x[n]; arrayinitialize(x,0.0); in Indicator the array should be the type "double x[]; SetIndexBuffer(0,x);" or "double x[n];"

 
vx0532:


sorry, int i=100; should be int i=0; now it is ok; and in EA array also can receive iCustom()'s return.

Thanks.

Now I know. In the fact the arrays, like x[], only can be used in Indicator not in EA;

No, that is not correct unless you are talking about a buffer ? there is a difference between buffers and arrays. You can declare an array such as x[] in an EA but you need to resize it before you use it otherwise it has zero elements.
 
RaptorUK:
No, that is not correct unless you are talking about a buffer ? there is a difference between buffers and arrays. You can declare an array such as x[] in an EA but you need to resize it before you use it otherwise it has zero elements.


thank you

so when we use array in EA, the array must be confirmed its size before its use; but in Indicator, that is an other story.

in the addition, in EA and Indicator shall we resize array, such as x[n]?

Reason: