TEMA
Download scriptThis tool is a custom technical analysis indicator designed to provide traders with a smoothed visualization of price movements on a trading chart. While standard moving averages are often used to identify trends, this specific script calculates a more sophisticated metric known as the Triple Exponential Moving Average (TEMA).
How it Works
The core logic of this script relies on "layering" mathematical averages to reduce the delay typically found in standard indicators. Most moving averages lag behind the current market price; this script overcomes that limitation by performing a three-step calculation process:
- Primary Average: The script first calculates a standard Exponential Moving Average (EMA) based on a user-defined period (defaulting to 14).
- Secondary and Tertiary Layers: It then takes the results of that first average and calculates an "average of the average," and subsequently an "average of the average of the average." This creates multiple layers of smoothed data.
- Final Calculation: Finally, the script applies a specific mathematical formula—weighting these three layers against each other—to produce the final TEMA line.
Key Benefits for the User
- Reduced Lag: By calculating averages on top of averages, the indicator reacts more quickly to recent price changes compared to a traditional moving average.
- Smoother Visualization: It filters out "market noise" (minor, insignificant price fluctuations), making it easier for a trader to see the underlying trend clearly.
- Customizable Sensitivity: The user can adjust the
EMA_periodinput to make the indicator more sensitive to rapid price changes or more stable for identifying long-term trends.
In practical terms, this script provides a responsive, smooth line on your chart that helps identify the momentum of the market while attempting to stay as close to the current price action as possible.
//+------------------------------------------------------------------+
//| TEMA.mq4 |
//| Copyright © 2007, MetaQuotes Software Corp. |
//| http://www.metaquotes.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link "http://www.metaquotes.ru/"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DarkBlue
#property indicator_width1 2
//---- input parameters
extern int EMA_period=14;
//---- buffers
double TemaBuffer[];
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(4);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TemaBuffer);
SetIndexBuffer(1,Ema);
SetIndexBuffer(2,EmaOfEma);
SetIndexBuffer(3,EmaOfEmaOfEma);
IndicatorShortName("TEMA("+EMA_period+")");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit,limit2,limit3,counted_bars=IndicatorCounted();
//----
if (counted_bars==0)
{
limit=Bars-1;
limit2=limit-EMA_period;
limit3=limit2-EMA_period;
}
if (counted_bars>0)
{
limit=Bars-counted_bars-1;
limit2=limit;
limit3=limit2;
}
for (i=limit;i>=0;i--) Ema[i]=iMA(NULL,0,EMA_period,0,MODE_EMA,PRICE_CLOSE,i);
for (i=limit2;i>=0;i--) EmaOfEma[i]=iMAOnArray(Ema,0,EMA_period,0,MODE_EMA,i);
for (i=limit3;i>=0;i--) EmaOfEmaOfEma[i]=iMAOnArray(EmaOfEma,0,EMA_period,0,MODE_EMA,i);
for (i=limit3;i>=0;i--) TemaBuffer[i]=3*Ema[i]-3*EmaOfEma[i]+EmaOfEmaOfEma[i];
//----
return(0);
}
//+------------------------------------------------------------------+
Comments