IncBandsOnArray – library MetaTrader 5

The CBandsOnArray is intended for calculation of Bollinger Bands ® (BB) on an indicator buffer.

Usage:

The Init() method with the following parameters is called in the OnInit() function of the indicator:

  • int aPeriod is indicator period;
  • ENUM_MA_METHOD aMethod is a method of averaging for calculation of the standard deviation;
  • double aDeviation is a width of bands (the number of standard deviations).

The Solve() method with the following parameters is called in the OnCalculate() function:

  • const int aRatesTotal is the rates_total variable from the OnCalculate() function parameters;
  • const int aPrevCalc is the prev_calculated variable from the OnCalculate() function parameters;
  • double aData[] is a buffer with data for the indicator calculation;
  • double & aMA[] is a buffer with calculated values of the central line;
  • double & aUpper[] is a buffer with calculated values of the upper line;
  • double & aLower[] is a buffer with calculated values of the lower line.

Additional methods:

  • int BarsRequired returns the minimal number of bars required for the indicator calculation;
  • string Name() returns a string with the indicator name.

The Test_BandsOnArrayArray.mq5 is an indicator demonstrating how to use the class. The IncBandsOnArray must be located in the MQL5\Include\IncOnArray directory of the terminal data folder (the IncOnArray must be created). The CMAOnArray class for the IncMAOnArray file is required for this class for work.

Alternative:  DayOfWeekLabels - indicator MetaTrader 5

Bollinger Bands ® Technical Indicator (BB) is similar to Envelopes. The only difference is that the bands of Envelopes are plotted a fixed distance (%) away from the moving average, while the Bollinger Bands are plotted a certain number of standard deviations away from it. Standard deviation is a measure of volatility, therefore Bollinger Bands adjust themselves to the market conditions. When the markets become more volatile, the bands widen and they contract during less volatile periods.

An example of using the CBandsOnArray class


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks