ma_TemaTma_rlh_smzDS

Download script
ma_TemaTma_rlh_smzDS

This script provides a sophisticated technical analysis tool designed to help traders identify market trends with greater precision and less "noise" than standard moving averages. It is based on the Triple Exponential Moving Average (TEMA) formula, which is specifically engineered to reduce the lag typically associated with traditional smoothing indicators.

Core Logic and Methodology

The primary objective of this indicator is to track price action while reacting more quickly to significant market turns. To achieve this, the script performs a multi-layered calculation involving three distinct stages of moving averages:

1. The Foundation (Exponential Moving Averages) The script begins by calculating a standard Exponential Moving Average (EMA). Unlike a simple average, an EMA gives more weight to recent price data, making it more responsive to current market conditions.

2. The Recursive Smoothing Process To refine the data even further, the script takes that initial EMA and calculates an "EMA of the EMA," and then a third layer, the "EMA of the EMA of the EMA." By nesting these calculations, the tool filters out minor price fluctuations (market noise) while maintaining a closer connection to the overall trend.

3. The TEMA Formula The core logic follows a specific mathematical weighting: it takes three times the first average, subtracts three times the second average, and adds the third average back in. This specific combination allows the resulting line to "track" the price very closely, significantly reducing the delay (lag) that traders usually experience when using standard indicators.

Visual Components and Data Output

The indicator populates your chart with several data points to provide a comprehensive view of market momentum:

  • The Base Trend: The primary TEMA line acts as the main signal for trend direction.
  • Signal Smoothing (SMZ): The script applies an additional smoothing layer to the TEMA to create a "Signal Line." This helps in identifying potential entry and exit points by observing how the main trend interacts with this secondary smoothed path.
  • Trend Deviation (DS): A third calculation is performed on the signal line to provide a deviation or distance metric, offering an extra dimension of data regarding the strength or momentum of the current move.

Practical Application for Traders

By utilizing this multi-layered approach, the script allows you to see a "cleaner" version of the market trend. Because it minimizes lag, it can signal potential reversals or trend continuations faster than a standard moving average might. It is designed to be highly customizable, allowing users to adjust periods and pricing modes to suit different timeframes—from fast-paced scalping to long-term trend following.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
ma_TemaTma_rlh_smzDS
//+------------------------------------------------------------------+
//|                                                       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  Aqua
#property  indicator_color5  Blue
#property  indicator_color6  RoyalBlue

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

#property  indicator_style1  2
#property  indicator_style2  2
#property  indicator_style3  2
#property  indicator_style4  0
#property  indicator_style5  0
#property  indicator_style6  0




//----
extern int MA_Period =13;
extern int MA_Mode   =3;
extern int MA_Price  =PRICE_TYPICAL;
extern string  MA_Method_Price = "SMA0 EMA1 SMMA2 LWMA3||0O,1C 2H3L,4Md 5Tp 6WghC: Md(HL/2)4,Tp(HLC/3)5,Wgh(HLCC/4)6";

extern int smz_Period   =3;
extern int smz_Mode     =3;
extern bool showTemaSmz    = true;
extern int ds_Period    =3;
extern int ds_Mode      =3;
extern int ds_Shift     =1;

extern bool drawmas        = false;

//---- buffers
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];
double Tema[];
double Temasl[];
double Temads[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   if  (drawmas) int draw = DRAW_LINE; else draw = DRAW_NONE;
   
   SetIndexStyle(0,draw);
   SetIndexStyle(1,draw);
   SetIndexStyle(2,draw);
   SetIndexStyle(3,draw);

   SetIndexStyle(4,draw);
   if(showTemaSmz) 
   SetIndexStyle(4,DRAW_LINE);
  
   SetIndexStyle(5,DRAW_LINE);
   SetIndexShift(5,ds_Shift);
   
   SetIndexDrawBegin(0,MA_Period);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
   if(!SetIndexBuffer(0,Ema) &&
      !SetIndexBuffer(1,EmaOfEma) &&
      !SetIndexBuffer(2,EmaOfEmaOfEma) &&
      !SetIndexBuffer(3,Tema)&&
      !SetIndexBuffer(4,Temasl)&&
      !SetIndexBuffer(5,Temads))
      Print("cannot set indicator buffers!");
   //   if(!SetIndexBuffer(0,Tema) )
   //      Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName(" TMA ("+MA_Period+","+MA_Mode+";" +smz_Period+"," +ds_Period+") ");
//      Tema[i]=3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
   SetIndexLabel(0,"ma");
   SetIndexLabel(1,"maofma");
   SetIndexLabel(2,"maOfmaOfma");
   SetIndexLabel(3,"tma");
   SetIndexLabel(4,"tma sigln");
   SetIndexLabel(5,"tma ds");




//---- 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,MA_Period,0,MODE_EMA,PRICE_CLOSE,i);
   for(i=limit; i >=0; i--)
      EmaOfEma[i]=iMAOnArray(Ema,Bars,MA_Period,0,MODE_EMA,i);

   for(i=limit; i >=0; i--)
      EmaOfEmaOfEma[i]=iMAOnArray(EmaOfEma,Bars,MA_Period,0,MA_Mode,i);
   
   //==========               
  
   for(i=limit; i >=0; i--)
      Tema[i]=3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
   
   for(i=limit; i >=0; i--)
      Temasl[i]=iMAOnArray(Tema,Bars,smz_Period,0,smz_Mode,i);
   for(i=limit; i >=0; i--)
      Temads[i]=iMAOnArray(Temasl,Bars,ds_Period,0,ds_Mode,i);



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

Comments