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


The CStochasticOnRingBuffer class is designed for calculating the technical indicator Stochastic Oscillator ( Stochastic Oscillator ) ring buffer using the following algorithm.
Class CStochasticOnRingBuffertitle
#includeFiles of the CStochasticOnRingBuffer.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 for class RingBuffer and class Moving Average must also be in this folder.
//--- Initialization method: Boolean initialization ( // Return false if error, true if successful integer period_k = 5 , // Period %K integer period_d = 3 , // Period %D integer period_s = 3 , // Deceleration %K period ENUM_MA_METHOD method = mode_SMA , // Method %D integer Buffer size = 256 , // The size of the ring buffer, the amount of stored data 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, // size of the array constant integer previously calculated, // elements processed on the last call constant double & high [] // maximum value array constant double & low [] // minimum value array constant double & close [] // array of closing prices );
//--- Array-based calculation method for individual series elements double the primary value ( // returns a random value constant integer of the collection element rate_total, // the size of the element constant integer previously calculated, // the processed array element constant integer start, // where the important data of the array begins constant double the high, // the maximum value constant double the low, // the minimum value constant integer the close, // the closing price 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 Thin Line Name Signal(); // Returns the name of the signal line indicator string method(); // Returns the smooth method as a line of text Integer period K() // Returns the period of %K Integer period S() // Returns the period of deceleration %K Integer period D() // Returns the period of %D 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 stochastic indicator: #includeCStochasticOnRingBuffer st; ... //+----------------------------------------------------------------------------------+ //|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: st.MainOnArray(rates_total, prev_calculated, highest price, lowest price, closing price); ... //--- use data from ring buffer "st", // For example, copy the data in the indicator buffer: for ( integer i = start;i Stopped();i++) { MainBuffer[i] = st[rates_total- 1 -i]; // The main line of the indicator SignalBuffer[i] = st.signal[rates_total- 1 -i]; // The signal line of the indicator } ... //--- 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_Stochastic_OnArrayRB.mq5 with ring buffer size of 256 elements When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used. 📎 cmaonringbuffer.mqh (14.9 KB) 📎 carrayring.mqh (6.64 KB) 📎 cstochasticonringbuffer.mqh (13.83 KB) 📎 test_stochastic_onarrayrb.mq5 (3.71 KB) 📎 test_stochastic_onvaluerb.mq5 (4.87 KB) Source: MQL5 #1372

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