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
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
Markus
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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....