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


The COsMAOnRingBuffer class is designed to calculate the technical indicator Moving Average Oscillator ( Oscillator Moving Average , OsMA) using an algorithmic ring buffer .
Class COsMAOnRingBuffer: publicCArrayRing
title
#includeFiles of the COsMAOnRingBuffer.mqh class should 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 with Ring Buffer , Smoothed Convergence and Divergence Moving Average and Moving Average classes should also be located in this folder.
//--- Initialization method: Boolean initialization ( // returns false if error, returns true integer if successful fast_period = 12 , // period integer for fast moving average smoothing slow period = 26 , // period integer for slow moving average smoothing signal period = 9 , // period for signal moving average smoothing ENUM_MA_METHOD fast method = mode_EMA , // Fast moving average smoothing method ENUM_MA_METHOD slow method = mode_EMA , // Slow moving average smoothing method ENUM_MA_METHOD signal method = mode_SMA , // signal moving average smoothing method integer 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 the usual 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 value of the osma set 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 constant double , // the important element of the array 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 String quick method() // Smooth method that returns a quick line as a line of text String slow method() // Method that returns smooth slow lines as lines of text String signal method() // Returns the smoothong method of the signal line in the form of a text line Integer fast period() // Returns the smooth period of the fast line Integer slow period() // Returns the period of the smooth slow line Integer signal period() // Returns the period smoothing of the signal line 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 Osma with indicator calculation methods: #includeOsmaOnRingBuffer.mqh > C OsmaOnRingBuffer osma; ... //+----------------------------------------------------------------------------------+ //|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: osma.MainOnArray(rates_total,prev_calculated,price); ... //--- use data from the "osma" ring buffer, // Copy the data in the indicator buffer: for ( integer i=start;i1 -i]; // indicator histogram //--- 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_OsMA_OnArrayRB.mq5 with ring buffer size of 256 elements. When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used. 📎 cosmaonringbuffer.mqh (8.35 KB) 📎cmacdonringbuffer.mqh (9.86 KB) 📎 cmaonringbuffer.mqh (14.9 KB) 📎 carrayring256.mqh (4.1 KB) 📎test_osma_onvaluerb.mq5 (3.64 KB) 📎test_osma_onarrayrb.mq5 (3.11 KB) Source: MQL5 #1367

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