Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Class for drawing ADX Wilder using ring buffer - MetaTrader 5 Script - MT4/MT5 Resources

author EAcpu | 5 reads | 0 comments |

The class for drawing the ADX Wilder using the ring buffer - indicator for MetaTrader 5

The class for drawing the ADX Wilder using the ring buffer - indicator for MetaTrader 5

The CADXWOnRingBuffer class is designed to calculate the technical indicator Average Directional Movement Index Wilder ( Average Directional Movement Index Wilder , ADX Wilder) using the ring buffer algorithm.

 Class CADXWOnRingBuffer

title

 #include

Files of the CADXWOnRingBuffer.mqh class should be placed in the IncOnRingBuffer folder that needs to be created in MQL5\Include\. Attached to the description are two files containing examples used by the classes in this folder. Files for class RingBuffer and class Moving Average must also be in this folder.

 //--- Initialization method:
Boolean initialization ( // Return false if error, true if successful integer ma_period = 14 , // Period of moving average smoothing ENUM_MA_METHOD ma_method = mode_SMMA , // Integer of moving average smoothing method Buffer size = 256 , // Size of ring buffer, number of stored data Boolean as_series = Error // true if it is a time series; false if it is a regular index of the input data );
 //--- Calculation method based on time series or indicator buffer:
Integer MainOnArray( // Returns the number of elements processed constant integer rate_total, // size of the array constant integer previously calculated, // elements processed on the last call constant double & high [] // maximum value array constant double & low [] // minimum value array constant double & close [] // array of closing prices );
 //--- Array-based calculation method for individual series elements
double primary value ( // returns the ADXW value of the collection element constant integer rate_total, // size of the array constant integer previously calculated, // handles the elements of the array constant integer start, // where the important data of the array begins constant double high, // maximum constant double low, // minimum constant double close, // closing price constant int index // element index );
 //--- Methods to access data:
Integer BarRequired(); // Returns the number of bars required to draw the indicator
String name ADXW(); // Returns the name of the indicator
String name NDI(); // Returns the name of the negative movement indicator line
Thin string name PDI(); // Returns the name of the positive indicator line Thin string MA method(); // Returns the smoothing method in the form of a text line
Integer MAPeriod(); // Returns the smoothing period
integer size(); // Returns the size of the ring buffer

Calculated data of the indicator can be obtained from the ring buffer just like from a usual array. For example:

#include CADXWOnRingBuffer adxw;

... //+----------------------------------------------------------------------------------+
//|Custom indicator iteration function |
//+------------------------------------------------------------------+
integer calculation ( const integer rate_total,
constant integer previously calculated,
const datetime &time[],
const double & open[],
const double &high[],
const double &low[],
const double &close[],
constant long &scale[],
const long &volume[],
const int & spread[])
  { //--- Indicator calculation: adxw.MainOnArray(rates_total, prev_calculated, highest price, lowest price, closing price);

  ...
//--- copy data from the "adxw" ring buffer in the indicator: for ( integer i = start; i  1 -i]; // Average directional movement index Wilder PDI_Buffer[i] = adxw.pdi[rates_total- 1 -i]; // Positive direction indicator NDI_Buffer[i] = adxw.ndi[rates_total- 1 -i]; // Negative direction indicator }

  ...
  }

Note that the index in the ring buffer is the same as the time series .

The class for drawing the ADX Wilder using the ring buffer - indicator for MetaTrader 5

Working result of Test_ADXW_OnArrayRB.mq5, ring buffer size is 256 elements

The class for drawing the ADX Wilder using the ring buffer - indicator for MetaTrader 5
Working result of Test_ADXW_OnValueRB.mq5, ring buffer size is 256 elements

When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used.


Attachment download

📎 cmaonringbuffer.mqh (14.9 KB)

📎 carrayring.mqh (6.64 KB)

📎 cadxwonringbuffer.mqh (10.95 KB)

📎test_adxw_onarrayrb.mq5 (3.93 KB)

📎test_adxw_onvaluerb.mq5 (5.66 KB)

Source: MQL5 #1356

Verification code Refresh