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

author EAcpu | 5 reads | 0 comments |

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

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

The CMFIOnRingBuffer class is designed to calculate the technical indicator Money Flow Index ( Money Flow Index , MFI) using an algorithmic ring buffer .

 Class CMFIOnRingBuffer: publicCArrayRing

title

 #include

The file of the CMFIOnRingBuffer.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, // if successful - true integer period = 14 , // period of MFI ENUM_MA_METHOD method = mode_SMA , // smoothibg method ENUM_APPLIED_PRICE apply price = price_TYPICAL , // price used for calculation ENUM_APPLIED_VOLUME applied volume = volume_scale , // integer volume used for calculation buffer size = 256 , // size of ring buffer boolean as_series = false // true if time series, otherwise - false );
 //--- 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 & open[], // open price constant double & high[], // highest price constant double & low[], // lowest price constant double & close[], // Closing price constant long & tick volume [], // Quotation volume constant long & volume []); // Inventory quantity );
 //--- Array-based calculation method for individual series elements
Double the main value ( // returns the MFI value constant integer of the collection element (bar) rate_total, // the size of the array constant integer previously calculated, // the processed array element constant integer start, // where the important data of the array begins constant double the open, // the opening price of the bar constant double the high one, // the maximum price of the bar constant double the low one, // Lowest price constant of bar double close, // Bar close price constant long tick amount, // Bar live volume constant long volume, // Bar stock constant integer index // element (bar) index );
 //--- Methods to access data:
Integer BarRequired(); // Returns the number of bars required to draw the indicator
string name(); // returns the name of the indicator
integer period (); // returns period
String method(); // Return this method as a line of text
ENUM_APPLIED_PRICE price(); // Returns the type of price used
ENUM_APPLIED_VOLUME volume(); // Returns the type of used volume
integer size(); // Returns the size of the ring buffer

You can get the pointer from the ring buffer just like you would from a normal array.Target calculation data. For example:

//--- Class with MFI indicator calculation method:
#include CMFIOnRingBuffer mfi;

... //+----------------------------------------------------------------------------------+
//|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 based on time series: mfi.MainOnArray(rates_total, prev_calculated, opening price, highest price, lowest price, closing price, tick_volume, trading volume);

... //--- use data from ring buffer "mfi",
// For example, copy the data in the indicator buffer: for ( integer i = start;i  Stopped();i++)
      MFI_Buffer[i] = mfi[rates_total- 1 -i]; // Indicator line ... //--- Return the prev_calculated value for the next call: return (rates_total);
  }

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

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

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

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

📎 cmfionringbuffer.mqh (13.99 KB)

📎 cmaonringbuffer.mqh (14.9 KB)

📎 carrayring.mqh (6.64 KB)

📎 test_mfi_onarrayrb.mq5 (3.55 KB)

📎 test_mfi_onvaluerb.mq5 (3.98 KB)

Source: MQL5 #1395

Verification code Refresh