Array doesn't work in expert

 
I've been having problems using arrays in experts. I did a simple test below to load closing prices into an array in an expert and then print the results (output in the expert tab) - and all I get are 0.000000 instead of the closing prices. So apparently nothing is getting loaded into the array! no wonder none of my experts are working right where I rely on arrays to load data. Does anyone else have the same problem or can anyone shed some light on this?

i=0;
while(i<=10)
{
BWArray[i]=iClose(NULL,0,i);
Print("BWArray"+i+"= "+BWArray[i]);
i++;
}
 
I've been having problems using arrays in experts. I did a simple test below to load closing prices into an array in an expert and then print the results (output in the expert tab) - and all I get are 0.000000 instead of the closing prices. So apparently nothing is getting loaded into the array! no wonder none of my experts are working right where I rely on arrays to load data. Does anyone else have the same problem or can anyone shed some light on this?

i=0;
while(i<=10)
{
BWArray[i]=iClose(NULL,0,i);
Print("BWArray"+i+"= "+BWArray[i]);
i++;
}


Have you defined the array?
double BWArray[10];
 
Yes - output is always 0.0000
 
I noticed lately in some indicator that loading prices into Array (Series) can be unsuccesfull in the begining.
But after some time indicator managed data loading and started functioning. So perhaps some load completion handling is necessary... Try data load with some Sleep period, or repeat quotes loading in loop unitl success, or something like this. I hope it will work.

All the best

Rafael
 
I had this problem on some arrays that were incorrectly sized ... if you say you defined it as [10] this may not be the case but I think I'll mention it anyway. (Some indicators functions for example were called from included source code with the default arrays without calling SetIndicatorBuffer.)

If the array is too small, MQ4 will not complain but just access the values as zero. In my case (indicators that created a copy of the history etc.) had to call
ArrayResize(mycopy, Bars);
to always make the array large enough.

However, I tried your code and probably you are doing that in the init function. iClose() returns zeros there.

Try it in start like this:

       static bool didinit= false;
       static double BwArray[];

      if (!didinit) {
           TableResize(BwArray, Bars);
            // fill table
            didinit= true;
      }



Hope this helps.


Markus

 
Shimodax you rock!!

I did 2 things different and everything works now -
1st - I added an ArrayResize(BWArray,Bars)
2nd - added a loop to initialize all BWArray items to 0 before I did the calculations
for(i=0;i<=Bars;i++) BWArray[i]=0;

Everything (this post and the orther related post) works now - thanks for all your help!!!
 
@paul

Glad to have been of help

Markus

PS: Btw, ArrayInitialize(BWArray, 0.0) may be more elegant ;-)
Reason: