IncMACDOnArray – library MetaTrader 5

CMACDOnArray class is designed for calculation of MACD (Moving Average Convergence/Divergence, MACD) values on indicator buffers.

Usage:

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

  • int aFastPeriod – fast МА period;
  • int aSlowPeriod – slow МА period;
  • int aSignalPeriod – signal line period;
  • ENUM_MA_METHOD aFastMethod – fast МА method;
  • ENUM_MA_METHOD aSlowMetod – slow МА method;
  • ENUM_MA_METHOD aSignalMethod – signal line method.

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

  • const int aRatesTotal is a rates_total variable from the OnCalculate() function parameters;
  • const int aPrevCalc – prev_calculated variable from the OnCalculate() function;
  • double aData[] – the buffer with the data used for the indicator calculation;
  • double aFastMA[] – intermediate buffer for fast МА;
  • double aSlowMA[] –  intermediate buffer for slow МА;
  • double aMain[] – calculated value of MACD main line;
  • double aSignal[] – calculated value of MACD signal line.
 Additional methods:
  • int BarsRequiredSignal() – returns the minimum number of bars for the signal line calculation;
  • int BarsRequiredMain() – returns the minimum number of bars for the main line calculation;
  • string Name() – returns the line with the indicator name;
  • string NameMain() – returns the line with the indicator main line name;
  • string NameSignal() –  returns the line with the indicator signal line name;
  • string Names() – returns the line with МА names.
Alternative:  Chande's DMI - volatility ratio adaptive - indicator MetaTrader 5

Test_MACDOnArray.mq5 is a sample indicator showing CMACDOnArray class application. IncMACDOnArray file must be placed to MQL5\Include\IncOnArray of the terminal data folder (IncOnArray folder must be created).

CMAOnArray class from the IncMAOnArray file is needed for the proper work. It can be found here.

Moving Average Convergence/Divergence (MACD) is the next trend-following dynamic indicator. It indicates the correlation between two Moving Averages of a price.

Example of use of CMACDOnArray class


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