MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal

Source code library - Expert Advisors, Indicators and Scripts

MetaTrader Market: we have 650 Expert Advisors for algorithmic trading!
To post a new code, please log in or register

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

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

2012.01.20 11:45

IncTemaOnArray - library for MetaTrader 5

| English Russian Chinese Spanish Portuguese

votes: 13


The CTemaOnArray class is intended for calculation of TEMA (Triple Exponential Moving Average) on an indicator buffer.


The Init() method with the following parameters is called in the OnInit() function of the indicator:

The Solve() method with the following parameters is called in the OnCalculate() function:

  • const int aRatesTotal is the rates_total variable from the OnCalculate() function parameters;
  • const int aPrevCalc is the prev_calculated variable from the OnCalculate() function parameters;
  • double aData[] is a buffer with data for the indicator calculation;
  • double aM1[] is an intermediate buffer for calculations;
  • double aM2[] is an intermediate buffer for calculations;
  • double aM3[] is an intermediate buffer for calculations;
  • double aTEMA[] is the buffer with calculated values of the indicator.
Additional methods:
  • int BarsRequired() returns the minimum number of bars required for the indicator calculation;
  • string Name() returns a string with the indicator name;

Test_TemaOnArray.mq5 is an indicator demonstrating how to use the CTemaOnArray class. The IncTemaOnArray file must be located in the MQL5\Include\IncOnArray directory of the terminal data folder (the IncOnArray folder must be created). The CMAOnArray class for the IncMAOnArray file is required for this class for work.

Triple Exponential Moving Average Technical Indicator (TEMA) was developed by Patrick Mulloy and published in the "Technical Analysis of Stocks & Commodities" magazine. The principle of its calculation is similar to DEMA (Double Exponential Moving Average). The name "Triple Exponential Moving Average" does not very correctly reflect its algorithm. This is a unique blend of the single, double and triple exponential smoothing average providing the smaller lag than each of them separately.


An example of using the CTemaOnArray class

Translated from Russian by MetaQuotes Software Corp.
Original code:

Last comments | Go to discussion (1)
Alexander Piechotta
FinGeR | 30 Jan 2013 at 19:51
in MaxBars = 500;
int limit=(int)MathMin(rates_total-prev_calculated,MaxBars);

I want to have only the current 50 bars calculated and displayed.

How do I change the code?