Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

Indicators

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

| English Русский 中文 Español Deutsch 日本語 Português

Views:
3049
Rating:
votes: 19
Published:
2013.01.18 13:00
Updated:
2016.11.22 07:32
\MQL5\Include\IncOnRingBuffer\
carrayring.mqh (6.64 KB)view
\MQL5\Indicators\OnRingBuffer\

Description

The CFractalsOnRingBuffer is designed for calculation of the Fractals technical indicator (Fractals) using the algorithm of the ring buffer

Declaration

class CFractalsOnRingBuffer

Title

#include <IncOnRingBuffer\CFractalsOnRingBuffer.mqh>

File of the CFractalsOnRingBuffer.mqh must be placed in the IncOnRingBuffer folder that need to be established in MQL5\Include\. Two files with the examples used by the class from this folder are attached to the description. File with the class of the ring buffer also must be in this folder.

Class methods

//--- initialization method:
bool Init(                      // if error it returns false, if success - true
   int  bars_right  = 2,        // the number of bars to the right from the extremum
   int  bars_left   = 2,        // the number of bars to the left from the extremum
   int  size_buffer = 256,      // the size of the ring buffer
   bool as_series   = false     // true, if a time series, otherwise - false
   );
//--- the method of calculation based on a time series or the indicator buffers:          
int MainOnArray(                  // returns the number of processed elements  
   const int     rates_total,     // the size of the arrays
   const int     prev_calculated, // processed elements on the previous call
   const double& high[],          // the array of the maximum
   const double& low[],           // the array of the minimum
   );
//--- the method of calculation of fractal based on a separate series elements of the array high[]          
double MainOnHigh(               // returns the value of up fractal for the index-bars_right element (bar)
   const int    rates_total,     // the size of the array
   const int    prev_calculated, // processed elements of the array
   const int    begin,           // from where the significant data of the array starts
   const double high,            // the current bar maximum
   const int    index            // the current element (bar) index
   );
//--- the method of calculation of down fractal based on a separate series elements of the array low[]          
double MainOnLow(                // returns down fractal value for the index-bars_right element (bar)
   const int    rates_total,     // the size of the array
   const int    prev_calculated, // processed elements of the array
   const int    begin,           // from where the significant data of the array starts
   const double low,             // the current bar minimum, the current array element maximum 
   const int    index            // the current element (bar) index
   );
//--- the methods of access to the data:
int    BarsRequired();  // Returns the necessary number of bars to draw the indicator
string Name();          // Returns the name of the indicator
string NameUpper()      // Returns the name of up fractals
string NameLower()      // Returns the name of down fractals
int    BarsRight()      // Returns the number of bars to the right from the extremum
int    BarsLeft()       // Returns the number of bars to the left from the extremum
int    Size();          // Returns the size of the ring buffer

To get the calculated data of the indicator from the ring buffers is possible as from the usual array. For example:

//--- the class with the methods of calculation of the Fractals indicator:
#include <IncOnRingBuffer\CFractalsOnRingBuffer.mqh>
CFractalsOnRingBuffer fractals;

...

//+------------------------------------------------------------------+
//| Custom indicator iteration 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[])
  {
//--- calculation of the indicator based on the price time series:
   fractals.MainOnArray(rates_total,prev_calculated,high,low);

...

//--- use the data from the ring buffers "fractals",
//    for example, copy the data in the indicator buffer:
   for(int i=start;i<rates_total-BarsRight && !IsStopped();i++)
     {
      UpperBuffer[i] = fractals.upper[rates_total-1-i]; // up fractals
      LowerBuffer[i] = fractals.lower[rates_total-1-i]; // down fractals
     }

...

//--- return value of prev_calculated for next call:
   return(rates_total);
  }

Please note that indexing in the ring buffers is the same as in the time series.

Examples

  1. The indicator calculates the Test_Fractals_OnArrayRB.mq5 file on the basis of the price time series. The MainOnArray() method application is demonstrated.
  2. The Test_Fractals_OnValueRB.mq5 file demonstrates the use of the MainOnValue() method. At first the Fractals indicator is calculated and drawn. Then on the basis of this indicator ring buffer one more Fractals is drawn. 


The result of the work of the Test_Fractals_OnArrayRB.mq5 with the size of the ring buffer of 256 elements



The result of the work of the Test_Fractals_OnValueRB.mq5 with the size of the ring buffer of 256 elements

 

When writing code the developments of MetaQuotes Software Corp.Integer and GODZILLA were used.

Translated from Russian by MetaQuotes Software Corp.
Original code: https://www.mql5.com/ru/code/1422

SuperWoodiesCCI SuperWoodiesCCI

The indicator realizes the trading strategy using the CCI

The class for drawing the TEMA using the ring buffer The class for drawing the TEMA using the ring buffer

The class is designed for calculation of the technical indicator Triple Exponential Moving Average (Triple Exponential Moving Average, TEMA) using the algorithm of the ring buffer.

Exp_CandleStop_Trailing Exp_CandleStop_Trailing

The Expert Advisor moves Stop Loss of the open position along the border of the channel built using CandleStop indicator

Exp_StepSto_v1 Exp_StepSto_v1

The Expert Advisor drawn on the basis of the signals of the StepSto_v1 stochastic oscillator