Voir comment télécharger gratuitement des robots de trading
Retrouvez-nous sur Twitter !
Rejoignez notre page de fans
Un script intéressant ?
Poster un lien vers celui-ci -
laisser les autres l'évaluer
Vous avez aimé le script ? Essayez-le dans le terminal MetaTrader 5
Indicateurs

The class for drawing the Momentum using the ring buffer - indicateur pour MetaTrader 5

Vues:
5073
Note:
(19)
Publié:
2013.01.14 11:59
Mise à jour:
2016.11.22 07:32
\MQL5\Include\IncOnRingBuffer\ \MQL5\Indicators\IncOnRingBuffer\
MQL5 Freelance Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance

Description

The CMomentumOnRingBuffer class is designed for calculation of the technical indicator Momentum (Momentum) using the algorithm of the ring buffer

Declaration

class CMomentumOnRingBuffer : public CArrayRing

Title

#include <IncOnRingBuffer\CMomentumOnRingBuffer.mqh>

File of the CMomentumOnRingBuffer.mqh class must be placed in the IncOnRingBuffer folder than 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, is successful - true
   int  period      = 14,   // the period of Momentum
   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 buffer:          
int MainOnArray(                  // returns the number of processed elements  
   const int     rates_total,     // the size of the array array[]
   const int     prev_calculated, // processed elements on the previous call
   const double& array[],         // the array of the input data
   );
//--- the method of calculation based on the separate series elements of the array           
double MainOnValue(               // returns value of Momentum for the set element
   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 long   value,            // the element value of the array
   const int    index             // the element index
   );
//--- the methods to access to the data:
int                 BarsRequired(); // Returns the necessary number of bars to draw the indicator
string              Name();         // Returns the name of the indicator
int                 Period();       // Returns the period
int                 Size();         // returns the size of the ring buffer

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

//--- the class with the methods of calculation of the Momentum indicator:
#include <IncOnRingBuffer\CMomentumOnRingBuffer.mqh>
CMomentumOnRingBuffer momentum;

...

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // the size of the array price[]
                 const int prev_calculated,  // processed bars on the previous call
                 const int begin,            // from where the significant data starts
                 const double& price[])      // the array for calculation
  {
//--- the calculation of the indicator based on time series:
   momentum.MainOnArray(rates_total,prev_calculated,price);

...
 
//--- use tha data of the "momentum" ring buffer,
//    for example, copy the data in the indicator buffer:
   for(int i=start;i<rates_total && !IsStopped();i++)
      Momentum_Buffer[i] = momentum[rates_total-1-i]; // the indicator line

...

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

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

Examples

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


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



The result of the work of the Test_Momentum_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.

Traduit du russe par MetaQuotes Ltd.
Code original : https://www.mql5.com/ru/code/1396

TrendEnvelopes TrendEnvelopes

The typical semaphore trend indicator.

ytg_Fractals_Price ytg_Fractals_Price

The indicator of fractals price levels

Breakout Bars Trend EA Breakout Bars Trend EA

The Expert Advisor based on the Breakout Bars Trend v2 indicator. In dependence of settings the entry is performed as in the trend reversal, so after missing the set number of false signals.

Exp_ColorXADX Exp_ColorXADX

The trading system based on change of the trend direction and force of the trend displayed by the ColorXADX indicator.