Array expert coding problem

 
I can handle arrays in indicators fine - but I'm obviously missing something simple when it comes to using them in an expert. Can someone offer suggestions on the below as to where I'm using the incorrect syntax? Trying to create a 10 period moving average on bandwidth and look for where the current (completed bar) bandwidth is crossing above the moving average of the bandwidth.

double Upper1, Lower1, Middle1; //Bollinger Bands for 1 bar ago (just completed)
double Upper2, Lower2, Middle2; //Bollinger Bands for 2 bars ago
double BW1, BW2; // Bandwidth
double BW_MA1, BW_MA2; //Bandwith Moving Average value
double BWArray[]; //Array to store Bandwith for moving average calculation

Upper1=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,1);
Lower1=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,1);
Middle1=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);
BW1=(Upper1-Lower1)/Middle1;

Upper2=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,2);
Lower2=iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,2);
Middle2=iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,2);
BW2=(Upper2-Lower2)/Middle2;

BWArray[i]=(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0)-iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0))/iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
i++;

BW_MA1=iMAOnArray(BWArray,0,10,0,MODE_EMA,1);
BW_MA2=iMAOnArray(BWArray,0,10,0,MODE_EMA,2);

if(BW1>BW_MA1 && BW2<BW_MA2)

etc....
 
MQL have bugs and has weak descriptions or help. So I always use many Print() function to check what's going on. First I suggest check values:

BW2=(Upper2-Lower2)/Middle2;

Print((iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0)-iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0))/iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0));

BWArray[i]=(iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0)-iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0))/iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
Print(BWArray[i]);

i++;
.....

If first print is 0 than you should check equation. If second than try define with value for ex. double BWArray[10000];

Rafael
 
Your BwArray seems to be unsized (use ArrayResize()). Also make sure you're not using this in the init() function (see my post in your other thread).


Markus
Reason: