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 AMA using ring buffer - MetaTrader 5 script | Forex indicator download - MT4/MT5 resources

author EAcpu | 5 reads | 0 comments |

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

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

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

The CAMAOnRingBuffer class is designed for calculating the technical indicator Adaptive Moving Average ( Adaptive Moving Average , AMA) using an algorithmic ring buffer .

 Class CAMAOnRingBuffer: public CArrayRing

title

 #include

Files of the CAMAOnRingBuffer.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. The files for the class ring buffer and class efficiency must also be in this folder.

 //--- Initialization method:
boolean initialization ( // returns false on error, true on success integer period = 10 , // AMA period integer fast_periods = 2 , // fast EMA period integer slow_periods = 30 , // slow EMA period integer size buffer = 256 , // size of ring buffer, amount of data to store 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 AMA 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, // the element value of the array 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
StringFastPeriod (); // Returns the fast EMA smoothed period
Integer slow period(); // Returns the slow EMA smoothed period
integer period(); // Returns the period of AMA
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 AMA indicator calculation method:
#include CAMAOnRingBuffer ama;

... //+----------------------------------------------------------------------------------+
//|Custom indicator iteration function |
//+------------------------------------------------------------------+
integer calculation ( const integer rate_total, 
constant integer previously calculated, 
Starting with a constant integer , 
const double &price[]) 
  { //--- Indicator calculation based on price time series: Ama.MainOnArray (rates_total,prev_calculated,price);

... //--- use the data from the ring buffer " ama ", // for example, copy the data from the indicator buffer: for ( integer i = start; i  Ama [rates_total- 1 -i]; // indicator line

//--- Return 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 .

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

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

The class for drawing the AMA using the ring buffer - indicator for MetaTrader 5
Working result of Test_AMA_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

📎 carrayring.mqh (6.64 KB)

📎ceronringbuffer.mqh (8.53 KB)

📎camaonringbuffer.mqh (8.96 KB)

📎 test_ama_onarrayrb.mq5 (2.9 KB)

📎 test_ama_onvaluerb.mq5 (3.37 KB)

Source: MQL5 #1375

Verification code Refresh