iMAOnArray problem

 

Hi everyone,

I experience problems while using iMAOnArray, so I isolated the problem.

If I do that inside the init() method of an indicator, this works :

int init()
{
 ...
 double t[10];
 for (int i = 0; i < 5; i++)  t[i] = i;
   Print("ma = " + iMAOnArray(t, 3, 3, 0, MODE_SMA, 0));
}

But if I use a global array :

...
double t[];
...
 
int init()
{
  IndicatorBuffers(2); // To set this array as an extra one
  ...
  SetIndexBuffer(1, t);
  ...
 
 for (int i = 0; i < 5; i++)
    t[i] = i;
 Print("ma = " + iMAOnArray(t, 3, 3, 0, MODE_SMA, 0));
}

then it won't work, and the iMAOnArray function always returns 0... I precise I already have an array declared to store the indicator data, "t" is the second.
Is there a problem with the declaration of t ?


Thanks in advance,
Mark

 
Note that your index buffer is like series array ie indexed from right to left. And iMAOnArray calculates from left to right. This problem was discussed on this forum
 

Hi stringo,

Well, of course I heard about that difference of indexation in the MQL4 manual. But I don't see what the problem is : I'm filling the array from 0 to 5, hence from left to right !
I've tried to call ArraySetAsSeries(t, false); just before the loop but it didn't work better.
Please, if you understood the problem, could you tell me how to solve it ?

Thanks,
Mark

Reason: