ma_TemaDema_rlh_sln

Download script
ma_TemaDema_rlh_sln

This technical indicator is designed to provide a more responsive and refined view of market trends by utilizing a sophisticated smoothing technique known as the Triple Exponential Moving Average (TEMA). Unlike standard moving averages, which can sometimes lag behind current price movements, this tool uses a multi-layered calculation to reduce delay while maintaining a smooth visual line.

How the Logic Works

The core logic relies on "nesting" multiple moving averages within one another. The script performs the following steps to generate its data:

  • Layered Averaging: It first calculates a standard Exponential Moving Average (EMA). It then takes that result and calculates another EMA from it, repeating this process a third time. This creates three distinct layers of smoothed data.
  • The TEMA Calculation: The primary "TEMA" line is produced by combining these three layers using a specific mathematical formula. By subtracting the second layer and adding back the third layer in a weighted fashion, the indicator effectively "cancels out" much of the lag typically found in traditional averages.
  • Double Exponential Average (DEMA): The script also calculates a DEMA, which provides an alternative variation of high-responsiveness smoothing by comparing the first and second layers of the calculation.

Visual Components on Your Chart

The indicator populates your trading screen with several distinct lines, each representing a different stage of this mathematical process:

  1. The Foundation (Red & Green Lines): These represent the basic EMA and the first "EMA of an EMA." They serve as the building blocks for the more complex calculations.
  2. The Smoothing Layers (Yellow Line): This represents the third layer (the "EMA of an EMA of an EMA").
  3. The Primary Signal (Aqua Line): This is the TEMA. It is the final product of the multi-layered formula and is generally considered the primary trend indicator for this tool.
  4. Alternative Signal (Blue Line): This represents the "Tema SLN," which applies an additional moving average over the TEMA to provide a secondary, even smoother signal line.

Summary for Traders

By using this logic, the indicator aims to show you the "true" direction of the market more quickly than a standard moving average would. It balances sensitivity and smoothness, helping to filter out minor market noise while staying closely glued to the actual price action.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
ma_TemaDema_rlh_sln
//+------------------------------------------------------------------+
//|                                                       TEMA_RLH   |
//|                                    Copyright © 2006, Robert Hill |
//|                                       http://www.metaquotes.net/ |
//|                                                                  |
//| Based on the formula developed by Patrick Mulloy                 |
//|                                                                  |
//| It can be used in place of EMA or to smooth other indicators.    |
//|                                                                  |
//| TEMA = 3 * EMA - 3 * (EMA of EMA) + EMA of EMA of EMA            |
//|                                                                  |
//|  Red is EMA, Green is EMA of EMA, Yellow is Ema of Ema of Ema    |
//|  Aqua is TEMA                                                    |
//|                                                                  |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2006, Robert Hill "
#property  link      "http://www.metaquotes.net/"
//---- indicator settings
#property  indicator_chart_window
#property  indicator_buffers 6
#property  indicator_color1  Yellow
#property  indicator_color2  Orange
#property  indicator_color3  Red
#property  indicator_color4  Green
#property  indicator_color5  Aqua
#property  indicator_color6  Blue

#property  indicator_width1  1
#property  indicator_width2  1
#property  indicator_width3  1
#property  indicator_width4  2
#property  indicator_width5  2
#property  indicator_width6  1

//----
extern int EMA_Period =14;
extern int temaSigLperiod =14;
//---- buffer
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];
double Dema[];
double Tema[];
double Temasln[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,DRAW_LINE);
   SetIndexStyle(4,DRAW_LINE);
   SetIndexStyle(5,DRAW_LINE);
   SetIndexDrawBegin(0,EMA_Period);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,Ema) &&
      !SetIndexBuffer(1,EmaOfEma) &&
      !SetIndexBuffer(2,EmaOfEmaOfEma) &&
      !SetIndexBuffer(3,Dema)&&
      !SetIndexBuffer(4,Tema)&&
      !SetIndexBuffer(5,Temasln))
      Print("cannot set indicator buffers!");
   //   if(!SetIndexBuffer(0,Tema) )
   //      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("TEMA("+EMA_Period+")");
//      Tema[i]=3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
   SetIndexLabel(0,"ema");
   SetIndexLabel(1,"emaofema");
   SetIndexLabel(2,"EmaOfEmaOfEma");
   SetIndexLabel(3,"dema");
   SetIndexLabel(4,"tema ");
   SetIndexLabel(5,"tema sln");




//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   int i, limit;
   int    counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   for(i=limit; i>=0; i--)
      Ema[i]=iMA(NULL,0,EMA_Period,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit; i >=0; i--)
      EmaOfEma[i]=iMAOnArray(Ema,Bars,EMA_Period,0,MODE_EMA,i);

   for(i=limit; i >=0; i--)
      EmaOfEmaOfEma[i]=iMAOnArray(EmaOfEma,Bars,EMA_Period,0,MODE_EMA,i);
   //==========             

   for(i=limit; i >=0; i--)
      Dema[i]=2 * Ema[i] - EmaOfEma[i];


   for(i=limit; i >=0; i--)
      Tema[i]=3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
   
//  int  per=( EMA_Period -1)/2;
   for(i=limit; i >=0; i--)
      Temasln[i]=iMAOnArray(Tema,Bars,temaSigLperiod,0,MODE_EMA,i);



//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments