This custom technical indicator is designed to provide traders with a more responsive and smoothed visualization of price action on a trading chart. By using a sophisticated multi-layered calculation, it aims to highlight the underlying trend while reducing the "noise" typically found in standard moving averages.
How It Works
The core logic of this script relies on a technique called Triple Exponential Smoothing. Instead of looking at price data in isolation, the indicator processes the information through three distinct layers of calculation:
- The Base Layer: The script first calculates a standard moving average based on your chosen settings (such as the time period and the specific type of price data).
- The Secondary Layer: It then takes that first moving average and calculates a second moving average of that result. This creates a much smoother curve.
- The Tertiary Layer: The process repeats a third time, creating an even deeper level of smoothing.
The Final Result: The TEMA Calculation
Once these three layers are established, the script combines them using a specific mathematical formula. By weighting the primary average more heavily and subtracting the smoothed secondary and tertiary layers, the tool achieves two main goals:
- Reduced Lag: Unlike traditional moving averages that can sometimes be "late" to react to sudden price changes, this method helps the indicator stay closer to the actual price movement.
- Enhanced Smoothness: It filters out minor market fluctuations, making it easier for traders to identify the primary direction of the trend without being distracted by insignificant price spikes.
Customization Options
Users have the flexibility to tailor the indicator's behavior to fit different trading styles:
- Maperiod: Adjusts how much historical data is considered (shorter periods are more reactive; longer periods are smoother).
- MAMethod: Allows you to choose between different moving average types (such as Simple, Exponential, or Linear Weighted) to change how the base data is weighted.
- MAPrice: Lets you decide which price point the indicator should track—whether it be the closing price, opening price, highs, lows, or a median of these values.
//+------------------------------------------------------------------+
//| TEMA_CUSTOM |
//| Copyright 2015, SergeyVrady |
//| |
//+------------------------------------------------------------------+
#property copyright "Sergey Vrady"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Yellow
#property indicator_width1 2
//---
input int MAPeriod=8;
input ENUM_MA_METHOD MAMethod=MODE_EMA;
input ENUM_APPLIED_PRICE MAPrice=PRICE_MEDIAN;
//---
double TemaBuffer[];
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];
//+------------------------------------------------------------------+
//| Initialization and input parameters |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TemaBuffer);
SetIndexBuffer(1,Ema);
SetIndexBuffer(2,EmaOfEma);
SetIndexBuffer(3,EmaOfEmaOfEma);
//---
IndicatorShortName("TEMA("+MAPeriod+")");
//---
string short_name;
int draw_begin=MAPeriod-1;
//---
switch(MAPrice)
{
case PRICE_CLOSE : short_name="CLOSE("; break;
case PRICE_OPEN : short_name="OPEN("; draw_begin=0; break;
case PRICE_HIGH : short_name="HIGH("; break;
case PRICE_LOW : short_name="LOW("; break;
case PRICE_MEDIAN : short_name="MEDIAN("; break;
case PRICE_TYPICAL : short_name="TYPICAL("; break;
case PRICE_WEIGHTED : short_name="WEIGHTED("; break;
default : return(INIT_FAILED);
}
//---
switch(MAMethod)
{
case MODE_SMA : short_name="SMA("; break;
case MODE_EMA : short_name="EMA("; draw_begin=0; break;
case MODE_SMMA : short_name="SMMA("; break;
case MODE_LWMA : short_name="LWMA("; break;
default : return(INIT_FAILED);
}
//---
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int deinit()
{
//---
return(0);
}
//+------------------------------------------------------------------+
//| Calculation section |
//+------------------------------------------------------------------+
int start()
{
int i,limit,limit2,limit3,counted_bars=IndicatorCounted();
//---
if(counted_bars==0)
{
limit=Bars-1;
limit2=limit-MAPeriod;
limit3=limit2-MAPeriod;
}
if(counted_bars>0)
{
limit=Bars-counted_bars-1;
limit2=limit;
limit3=limit2;
}
//---
for(i=limit;i>=0;i--) Ema[i]=iMA(NULL,0,MAPeriod,0,MAMethod,MAPrice,i);
for(i=limit2;i>=0;i--) EmaOfEma[i]=iMAOnArray(Ema,0,MAPeriod,0,MAMethod,i);
for(i=limit3;i>=0;i--) EmaOfEmaOfEma[i]=iMAOnArray(EmaOfEma,0,MAPeriod,0,MODE_EMA,i);
for(i=limit3;i>=0;i--) TemaBuffer[i]=3*Ema[i]-3*EmaOfEma[i]+EmaOfEmaOfEma[i];
//---
return(0);
}
//+------------------------------------------------------------------+
Comments