Bollinger Bands on Custom Array MQL5

 

I have a spread variable/array and I want to apply bollinger bands to it, but I cannot figure out how to do it. I searched everywhere and the only info I found is how to apply the iBands indicator on another indicator's data. But I found nothing about how to apply it on a custom array. Can anybody help please? Thank you.

Here is the code:

input string AssetA;
input string AssetB;

double AssetA_Close;
double AssetB_Close;
double Spread;

int OnInit(){  

   return(INIT_SUCCEEDED);
}


void OnTick(){

   AssetA_Close = iClose(AssetA, _Period, 1);
   AssetB_Close = iClose(AssetB, _Period, 1);
   Spread = AssetA_Close - AssetB_Close;  //Need to apply bollinger bands to this variable.
   
}
 
elean_trading:

I have a spread variable/array and I want to apply bollinger bands to it, but I cannot figure out how to do it. I searched everywhere and the only info I found is how to apply the iBands indicator on another indicator's data. But I found nothing about how to apply it on a custom array. Can anybody help please? Thank you.

Here is the code:

Bollinger Bands is the standard deviation derived from close and applied to the middle line.

You need to calculate the standard deviation from your series and then add and subtract it from your "middle" value...

 
Dominik Egert #:
Bollinger Bands is the standard deviation derived from close and applied to the middle line.

You need to calculate the standard deviation from your series and then add and subtract it from your "middle" value...

I would really appreciate if you could provide some info on how to achieve that with an array based on a specific lookback period? As even the iStDev function needs an indicator, similar to the iBands function, so I have no idea how to do it with an array. On MQL4 there was the iBandsOnArray/iStdDevOnArray function but on MQL5 there is no such option. Also not much info online on how to do it. Thank you!
 
elean_trading #:
I would really appreciate if you could provide some info on how to achieve that with an array based on a specific lookback period? As even the iStDev function needs an indicator, similar to the iBands function, so I have no idea how to do it with an array. On MQL4 there was the iBandsOnArray/iStdDevOnArray function but on MQL5 there is no such option. Also not much info online on how to do it. Thank you!
You can take a look at vectors and probably solve it with them with ease.



 
There is a function called iBandsOnArray for mql4, try to find it converted, or convert by yourself to mql5... You Can get the code of iBands and apply it to an array too...