TEMA_RLH

This tool is designed to provide a highly responsive and smoothed visual representation of price movements on a trading chart. It utilizes a sophisticated mathematical progression to filter out market "noise" while maintaining a closer proximity to current price action than standard moving averages typically offer.

Core Logic and Methodology

The indicator operates by layering multiple generations of Exponential Moving Averages (EMA). Instead of simply calculating one average, the script performs a nested calculation to create a "Triple" Exponential Moving Average (TEMA).

The logic follows these specific stages:

  • Primary Layer: The tool first calculates a standard Exponential Moving Average. This represents the basic trend of the price over a set period.
  • Secondary Layer: It then takes that first average and calculates an "Average of an Average." This process begins to smooth out the data further, reducing the impact of sudden, erratic price spikes.
  • Tertiary Layer: The script repeats the process once more, creating an "Average of an Average of an Average." This deep layering provides a stabilized foundation for the final calculation.

The Final Calculation (TEMA)

The actual line you see on your chart—the TEMA—is derived by combining these three layers using a specific weight distribution. By multiplying the primary average and subtracting the weighted components of the deeper averages, the formula effectively cancels out the "lag" that usually occurs in standard indicators.

Visual Representation

To help traders visualize this mathematical process, the script plots four distinct lines on the chart:

  1. Red Line: The basic Exponential Moving Average.
  2. Green Line: The first smoothed layer (Average of Average).
  3. Yellow Line: The second smoothed layer (Average of Average of Average).
  4. Aqua Line: The final TEMA. This is the primary indicator intended for use, highlighting the most accurate trend path by balancing smoothness with real-time responsiveness.

By providing all four layers, the tool allows you to see the "evolution" of the price trend, helping you identify whether the market is accelerating, decelerating, or maintaining a steady path.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
14 Views
0 Downloads
0 Favorites
TEMA_RLH
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                       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 4
#property  indicator_color1  Red
#property  indicator_color2  Green
#property  indicator_color3  Yellow
#property  indicator_color4  Aqua
#property  indicator_width1  1
#property  indicator_width2  1
#property  indicator_width3  1
#property  indicator_width4  2
      
extern int EMA_Period = 14;

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


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexStyle(3,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,Tema))
      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+")");
//---- initialization done
   return(0);
  }

int start()
{
   int i, limit;
   int    counted_bars=IndicatorCounted();
   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);
         
//========== COLOR CODING ===========================================               
        
   for(i = limit; i >=0; i--)
       Tema[i] = 3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
       
      return(0);
  }
//+------------------------------------------------------------------+



Comments