ma_trix2cd_rlh
Download scriptThis technical tool is designed to provide a more refined and responsive view of market trends by utilizing a sophisticated smoothing technique known as the Triple Exponential Moving Average (TEMA) logic. While standard moving averages are used to filter out "noise" from price action, they often suffer from significant lag—meaning they react slowly to sudden price changes. This script addresses that issue by layering multiple calculations on top of each other to create a highly sensitive yet smooth indicator.
How the Logic Works
The core functionality of this script relies on a multi-layered mathematical approach:
- Layered Smoothing: Instead of calculating a single average, the script calculates an Exponential Moving Average (EMA) and then performs "nested" calculations. It finds the average of the average, and then the average of that previous result.
- The TEMA Formula: By combining these layers—specifically taking three times the initial average, subtracting three times the "average of the average," and adding back the "average of the average of the average"—the script effectively cancels out most of the lagging delay found in traditional indicators.
- Dual-Period Analysis: The script performs this complex calculation across two different timeframes simultaneously (defined by the user as Period 1 and Period 2). This allows the tool to capture both immediate momentum shifts and broader trend movements.
Data Processing and Output
The script processes the market data in a specific sequence to arrive at its final visual output:
- Primary Calculation: It first tracks the raw price movement to generate the initial EMA sets for both periods.
- Secondary Smoothing: It then runs those results through the nested calculation process to create the "Triple" smoothed values.
- Rate of Change (ROC): Finally, it calculates the percentage difference between these smoothed values from one candle to the next. This transforms the data into a relative momentum value, showing how fast the trend is accelerating or decelerating.
User Experience
On the trading chart, this logic results in an indicator that reacts much faster to price fluctuations than a standard moving average would. By subtracting the secondary smoothed data from the primary one (a process controlled by a toggle in the settings), the script provides a "cleaned" signal that highlights the purity of the current market trend while filtering out minor, insignificant price flickers.
//+------------------------------------------------------------------+
//| 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 |
//| |
//+------------------------------------------------------------------+
//mod2009fxtsd tdcd (tema-dema)trix
#property copyright "Copyright © 2006, Robert Hill "
#property link "http://www.metaquotes.net/"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 DodgerBlue
#property indicator_width1 1
#property indicator_width2 1
//----
extern int EMA1_Period =9;
extern int EMA2_Period =13;
//extern int SigLperiod =9;
extern bool trixCD = true;
//---- buffer
double Ema11[];
double Ema12[];
double Ema13[];
double Ema21[];
double Ema22[];
double Ema23[];
double trix1[];
double trix2[];
//double txsln[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(8);
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(0,EMA2_Period);
SetIndexDrawBegin(1,EMA2_Period);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
SetIndexBuffer(7,Ema11);
SetIndexBuffer(6,Ema12);
SetIndexBuffer(5,Ema13);
SetIndexBuffer(4,Ema21);
SetIndexBuffer(3,Ema22);
SetIndexBuffer(2,Ema23);
SetIndexBuffer(1,trix1);
SetIndexBuffer(0,trix2);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("trix ( "+EMA1_Period+", "+EMA2_Period+" )");
// Tema[i]=3 * Ema[i] - 3 * EmaOfEma[i] + EmaOfEmaOfEma[i];
SetIndexLabel(0,"trix2");
SetIndexLabel(1,"trix1 ");
//---- 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--)
Ema11[i]=iMA(NULL,0,EMA1_Period,0,MODE_EMA,PRICE_CLOSE,i);
for(i=limit; i >=0; i--)
Ema12[i]=iMAOnArray(Ema11,Bars,EMA1_Period,0,MODE_EMA,i);
for(i=limit; i >=0; i--)
Ema13[i]=iMAOnArray(Ema12,Bars,EMA1_Period,0,MODE_EMA,i);
for(i=limit; i>=0; i--)
Ema21[i]=iMA(NULL,0,EMA2_Period,0,MODE_EMA,PRICE_CLOSE,i);
for(i=limit; i >=0; i--)
Ema22[i]=iMAOnArray(Ema21,Bars,EMA2_Period,0,MODE_EMA,i);
for(i=limit; i >=0; i--)
Ema23[i]=iMAOnArray(Ema22,Bars,EMA2_Period,0,MODE_EMA,i);
for(i=limit; i >=0; i--) if (Ema23[i+1]!=0)
{
trix2[i]= (Ema23[i]-Ema23[i+1])/Ema23[i+1];
if (trixCD) double t2= trix2[i];else t2=0.0;
}
for(i=limit; i >=0; i--) if (Ema13[i+1]!=0)
trix1[i]= (Ema13[i]-Ema13[i+1])/Ema13[i+1]-t2;
//----
return(0);
}
//+------------------------------------------------------------------+
Comments