거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Telegram에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
지표

The class for drawing the TEMA using the ring buffer - MetaTrader 5용 지표

조회수:
7781
평가:
(28)
게시됨:
2013.01.16 15:39
업데이트됨:
2016.11.22 07:32
\MQL5\Include\IncOnRingBuffer\ \MQL5\Indicators\OnRingBuffer\
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동

Description

The CTEMAOnRingBuffer 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.  

Declaration

class CTEMAOnRingBuffer : public CArrayRing

Title

#include <IncOnRingBuffer\CTEMAnRingBuffer.mqh>

File of the CTEMAOnRingBuffer.mqh class 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 classes of the ring bufferDEMA and Moving Average  also must be in this folder.

Class methods

//--- initialization method:
bool Init(                                // if error it returns false, if success - true
   int            period      = 12,       // the TEMA period
   ENUM_MA_METHOD method      = MODE_EMA, // the method of smoothing
   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 the processed elements  
   const int     rates_total,     // the size of the array
   const int     prev_calculated, // processed elements on the previous call
   const double& price[],         // the array for calculation
   );
//--- the method for calculation based on a separate series elements of the array           
double MainOnValue(              // returns the TEMA value for the set 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 value,           // the element (bar) value 
   const int    index            // the 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
int                 Period();        // Returns the period
int                 Size();          // Returns the size of the ring buffer
double              MA(int index);   // Returns the Moving Average value, indexing is like in a time series
double              DEMA(int index); // Returns the DEMA value, indexing is like a time series

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 TEMA indicator:
#include <IncOnRingBuffer\CTEMAOnRingBuffer.mqh>
CTEMAOnRingBuffer tema;

...

//+------------------------------------------------------------------+
//| 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
  {
//--- calculation of the indicator based on a time series:
    tema.MainOnArray(rates_total,prev_calculated,price);

...

//--- use the data from the "tema" ring buffer,
//    for example, copy the data in the indicator buffer:
   for(int i=start;i<rates_total && !IsStopped();i++)
      TEMA_Buffer[i] = tema[rates_total-1-i]; // the TEMA indicator line

...

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

When calculation the TEMA also calculation of the Moving Average and DEMA with the same parameters is performed. We can get the data from the MA ring buffer and DEMA using the MA method(int index) and DEMA(int index), respectively:

//--- use the data from the Moving Average and DEMA ring buffers,
//    for example, copy them in the indicator buffers:
   for(int i=start;i<rates_total && !IsStopped();i++)
     {
      MA_Buffer[i]   = dema.MA(rates_total-1-i);   // the Moving Average indicator line
      DEMA_Buffer[i] = dema.DEMA(rates_total-1-i); // the DEMA indicator line
     }

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

Examples

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


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



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

MetaQuotes Ltd에서 러시아어로 번역함.
원본 코드: https://www.mql5.com/ru/code/1417

Predict Predict

A semaphore, signal indicator with three variants of signals

StepMA_v6.4 StepMA_v6.4

A simple trend indicator of the NRTR type

SuperWoodiesCCI SuperWoodiesCCI

The indicator realizes the trading strategy using the CCI

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

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