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


The CEROnRingBuffer class is designed to calculate the technical indicator Efficiency Ratio (ER) used in Adaptive Moving Averages ( Adaptive Moving Average , AMA) algorithm using a ring buffer .
Class CEOnRingBuffer: publicCArrayRing
title
#includeFiles of the CEROnRingBuffer.mqh class must 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. A file ring buffer of class . must also be in this folder.
//--- Initialization method: Boolean initialization ( // Return false if error, true if successful integer period = 34 , // Calculate the period integer of ER size buffer = 256 , // Size of the ring buffer, the amount of data stored boolean as_series = false // 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, // the size of the array array[] const integer previously calculated, // the number of elements processed on the last call constant double & bulk[] // array of input values );
//--- //--- Array-based calculation method for individual series elements
double the primary value ( // returns the ER 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 place where the important data of the array starts constant integer the value of the // array element constant integer exponent // element index );//--- Methods to access data: Integer BarRequired(); // Returns the number of bars required to draw the indicator StringName () // Returns the name of the indicator integer period() // Returns the period of ER calculation 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:
//--- Class with ER indicator calculation method: #includeCEOnRingBufferer; ... //+----------------------------------------------------------------------------------+ //|Custom indicator iteration function | //+------------------------------------------------------------------+ integer calculation ( const integer rate_total, constant integer previously calculated, Starting with a constant integer , const double &price[]) { //--- Calculate indicators based on price time series: er.MainOnArray(rates_total,prev_calculated,price); ... //--- use data from ring buffer "er", // For example, copy the data in the indicator buffer: for ( integer i = start;i 1 - i]; // indicator line } //--- Returns the prev_calculated value for the next call: return (rate_total); }
Note that the index in the ring buffer is the same as the time series .
Working result of Test_ER_OnArrayRB.mq5, ring buffer size is 256 elements When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used. 📎 carrayring.mqh (6.64 KB) 📎ceronringbuffer.mqh (8.53 KB) 📎 test_er_onarrayrb.mq5 (2.75 KB) 📎 test_er_onvaluerb.mq5 (3.17 KB) Source: MQL5 #1374

Result of work of Test_ER_OnValueRB.mq5 with ring buffer size of 256 elements Attachment download
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •