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

author EAcpu | 5 reads | 0 comments |

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

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

The CRSIOnRingBuffer class is designed to calculate the technical indicator Relative Strength Index (RSI) ring buffer using the following algorithm.

 Class CRSIOnRingBuffer: publicCArrayRing

title

 #include

The file of CRSIOnRingBuffer.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. 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 period = 14 , // period of RSI ENUM_MA_METHOD method = mode_SMMA , // smoothing method integer buffer size = 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 RSI 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 begins constant double the value, // the array element value constant integer index // 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 period
string method(); // Return this method as a line of text
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 RSI indicator calculation method:
#include CRSOnRingBuffer rsi;

... //+----------------------------------------------------------------------------------+
//|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: rsi.MainOnArray(rates_total,prev_calculated,price);

... //--- use the data from the ring buffer "rsi", // for example, copy the data from the indicator buffer: for ( integer i = start; i  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 RSI using the ring buffer - indicator for MetaTrader 5

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

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

📎 crsionringbuffer.mqh (8.56 KB)

📎 cmaonringbuffer.mqh (14.9 KB)

📎 carrayring.mqh (6.64 KB)

📎 test_rsi_onarrayrb.mq5 (2.87 KB)

📎 test_rsi_onvaluerb.mq5 (3.31 KB)

Source: MQL5 #1385

Verification code Refresh