Class for drawing ADX using ring buffer - MetaTrader 5 script | Forex indicator download - MT4/MT5 resources



The CADXOnRingBuffer class is designed to calculate the technical indicator Average Directional Movement Index ( Average Directional Movement Index , ADX) using an algorithm ring buffer .
CADX on class ring buffertitle
#includeFiles of the CADXOnRingBuffer.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 success integer ma_period = 14 , // Moving average smoothing period ENUM_MA_METHOD ma_method = mode_EMA , // Moving average smoothing method integer buffer size = 256 , // Size of ring buffer, amount of stored data boolean as_series = false // true if time series, false if usual index of 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's primary value ( // returns the ADX value of the collection element constant integer rate_total, // the size of the array constant integer previously calculated, // the processed array element constant integer start, // the position starting from the valid value of the array constant double's high, // the maximum value constant double's low, // the minimum value constant integer close, // the closing price constant integer index // element index );
//--- Methods to access data: Integer BarRequired(); // Returns the number of bars required to draw the indicator String name ADX(); // Returns the name of the indicator String name NDI(); // Returns the name of the negative movement indicator line String name PDI(); // Return name positive movement indicator line String MA Method(); // Returns the smooth method as a line of text 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:
#includeCADXOnRingBuffer adx; ... //+----------------------------------------------------------------------------------+ //|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: adx.MainOnArray(rates_total, prev_calculated, highest price, lowest price, closing price); ... //--- copy data from "adx" ring buffer to indicator: for ( integer i = start;i 1 -i]; // Average directional movement index PDI_Buffer[i]=adx.pdi[rates_total- 1 -i]; // Positive direction indicator NDI_Buffer[i]=adx.ndi[rates_total- 1 -i]; // Negative direction indicator } ... }
Note that the index in the ring buffer is the same as the time series .
Working result of Test_ADX_OnArrayRB.mq5, ring buffer size is 256 elements When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used. 📎 cmaonringbuffer.mqh (14.9 KB) 📎 carrayring.mqh (6.64 KB) 📎 cadxonringbuffer.mqh (10.04 KB) 📎 test_adx_onarrayrb.mq5 (3.91 KB) 📎 test_adx_onvaluerb.mq5 (5.6 KB) Source: MQL5 #1343

Working result of Test_ADX_OnValueRB.mq5, ring buffer size is 256 elements Attachment download
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •