Description
Hey traders! Today, we're diving into the CStochasticOnRingBuffer class, which is crafted specifically for calculating the Stochastic Oscillator using a ring buffer algorithm. If you're looking to enhance your trading strategies with this powerful indicator, you’re in the right place!
Declaration
class CStochasticOnRingBuffer
Title
#include <IncOnRingBuffer\CStochasticOnRingBuffer.mqh>
Make sure to place the CStochasticOnRingBuffer.mqh file in the IncOnRingBuffer folder within your MQL5\Include directory. Don’t forget; you’ll also need the ring buffer class and the Moving Average class files in this folder for everything to work smoothly.
Class Methods
//--- initialization method: bool Init(// returns false if there's an error, true if successful int period_k = 5, // period %K int period_d = 3, // period %D int period_s = 3, // period of slowing %K ENUM_MA_METHOD method = MODE_SMA, // smoothing method for %D int size_buffer = 256, // size of the ring buffer bool as_series = false // true if a time series, false for regular indexing )
//--- main calculation method: int MainOnArray(// returns the number of processed elements const int rates_total, // size of the arrays const int prev_calculated, // processed elements in the last call const double &high[], // high values array const double &low[], // low values array const double &close[] // close prices array );
//--- calculation method using individual array elements: double MainOnValue(// returns Stochastic value for the given element const int rates_total, // size of the element const int prev_calculated, // processed elements const int begin, // starting point of significant data const double high, // maximum value const double low, // minimum value const double close, // close price const int index // element index );
//--- methods to access data: int BarsRequired(); // Returns the bars needed to draw the indicator string Name(); // Returns the indicator name string NameSignal(); // Returns the signal line name string Method(); // Returns smoothing method as text int PeriodK(); // Returns %K period int PeriodS(); // Returns slowing %K period int PeriodD(); // Returns %D period int Size(); // Returns ring buffer size
Accessing calculated data from the ring buffer is as straightforward as accessing a regular array. Here’s an example:
//--- class with Stochastic calculation methods: #include <IncOnRingBuffer\CStochasticOnRingBuffer.mqh> CStochasticOnRingBuffer st; ... //+------------------------------------------------------------------+ //| Custom indicator calculation function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime& time[], const double& open[], const double& high[], const double& low[], const double& close[], const long& tick_volume[], const long& volume[], const int& spread[]) { //--- indicator calculation based on price time series: st.MainOnArray(rates_total, prev_calculated, high, low, close); ... //--- using data from ring buffersRelated Posts
- Hourly Buffers for Data Collection in MetaTrader 5: A Simple Guide
- Unlocking MetaCOT 2: Your Ultimate CFTC Indicator Toolkit for MT4
- Mastering the MACD Candle Indicator for MetaTrader 4
- Unlocking the Power of Master Tools for MetaTrader 4
- Unlock Trading Insights with Volume Profile + Range v6.0 for MetaTrader 5