Class for drawing fractals using ring buffers - MetaTrader 5 Script | Forex Indicators Download - MT4/MT5 Resources


CFractalsOnRingBuffer is designed for calculating fractal technical indicators ( fractal ) ring buffers using the following algorithm.
ClassCFractalsOnRingBuffertitle
#includeThe CFractalsOnRingBuffer.mqh file 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 ( // false if error, true if successful integer right column = 2 , // integer number of bars to the right from the extreme value left column = 2 , // integer number of bars to the left of the extreme value buffer size = 256 , // size of the ring buffer boolean as_series = false // true if it is a 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, // the size of the array constant integer previously calculated, // the elements processed on the last call constant double & high[], // the largest array constant double & low[], // the array with the smallest value );
//--- Method to calculate fractal based on individual series elements of array high[] Double MainOnHigh( // returns the upper fractal value constant integer of the index-bars_right element (bar) rate_total, // size of the array constant integer previously calculated, // processed array element constant integer start, // where the important data of the array begins constant double high, // the maximum value of the current bar constant integer index // current element (bar) index );
//--- Method to calculate lower fractal based on individual series elements of array low[] Double the main open low ( // returns the lower fractal value of the index-bars_right element (bar) constant integer 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 low, // the current bar minimum value, the current array element maximum value constant integer index // the current element (bar) index );
//--- Methods to access data: Integer BarRequired(); // Returns the number of bars required to draw the indicator StringName (); // Returns the name of the indicator StringNameUpper () // Returns the name of the upper fractal String name Lower() // Returns the name of the lower fractal Integer right column() // Returns the number of bars to the right of the extreme value Integer left column() // Returns the number of bars to the left of the extreme value 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 methods for calculating fractal indicators: #includeCFractalsOnRingBuffer fractal; ... //+----------------------------------------------------------------------------------+ //|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 price time series: fractals.MainOnArray(rates_total,prev_calculated,high,low); ... //--- use data from ring buffer "fractal", // For example, copy the data in the indicator buffer: for ( integer i = start;i Stopped();i++) { UpperBuffer[i] = fractals.upper[rates_total- 1 -i]; // Upper fractal LowerBuffer[i] = fractals.lower[rates_total- 1 -i]; // Lower fractal } ... //--- 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 .
Working result of Test_Fractals_OnArrayRB.mq5 with ring buffer size of 256 elements When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used. 📎 cfractalsonringbuffer.mqh (10.84 KB) 📎 carrayring.mqh (6.64 KB) 📎 test_fractals_onarrayrb.mq5 (3.8 KB) 📎 test_fractals_onvaluerb.mq5 (4.98 KB) Source: MQL5 #1422

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