TRIX_A_Mulloy
Download scriptThis technical indicator is designed to provide traders with a smoothed visual representation of price momentum and trend changes. By analyzing historical price data, the script calculates a specific type of moving average that filters out "market noise," allowing for a clearer view of the underlying market direction.
How the Logic Works
The tool operates through a multi-layered mathematical process to arrive at its final visual output:
1. Triple Exponential Smoothing Instead of looking at raw price changes, which can be erratic, the script applies three successive layers of "Exponential Moving Averages" (EMA).
- The first layer identifies a general trend.
- The second and third layers are applied to the results of the previous layers. This nesting process significantly reduces market volatility, ensuring that the resulting data reflects long-term momentum rather than temporary price spikes.
2. The Triple Exponential Moving Average (TEMA) By combining these three layers of smoothing, the script calculates a "Triple Exponential Moving Average." This is a sophisticated calculation designed to reduce the "lag" typically found in standard moving averages. It attempts to react more quickly to actual trend reversals while remaining smooth enough to ignore insignificant price fluctuations.
3. The TRIX Calculation The core of the indicator is the TRIX line. The script calculates the percentage rate of change between the current TEMA value and its previous value. By converting this into a percentage, it allows traders to see how fast the trend is accelerating or decelerating.
4. The Signal Line To make the data more actionable, the script generates a second line known as the "Signal" line. This is a Simple Moving Average of the TRIX line itself. Think of this as an average of the momentum; when the primary TRIX line crosses over or under this signal line, it often suggests a potential shift in the market's trend.
Visual Interpretation
The indicator appears in a separate window below your main price chart. It provides two distinct lines:
- The Main Line (Blue): Represents the momentum of the market.
- The Signal Line (Red): Acts as a reference point to help identify potential turning points in that momentum.
By observing the relationship between these two lines, users can better identify when a trend is gaining strength or beginning to exhaust itself.
//+------------------------------------------------------------------+
//| DL_TRIX.mq4 |
//| Douglas Lozada |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Douglas Lozada"
#property link "http://www.metaquotes.net"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int Periodo = 12;
extern int Signal = 9 ;
//extern int Desplazar = 1;
//---- buffers
double TRIX_Buffer[];
double Signal_Buffer[];
double EMA1_buffer[];
double EMA2_buffer[];
double EMA3_buffer[];
double TEMA_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 3 additional buffers are used for counting.
IndicatorBuffers(6);
SetIndexBuffer(2,EMA1_buffer);
SetIndexBuffer(3,EMA2_buffer);
SetIndexBuffer(4,EMA3_buffer);
SetIndexBuffer(5,TEMA_buffer);
//---- indicators - drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,TRIX_Buffer);
SetIndexStyle(1,DRAW_LINE);
SetIndexDrawBegin(1,Signal);
SetIndexBuffer(1,Signal_Buffer);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("TRIX("+Periodo+","+Signal+")");
SetIndexLabel(0,"Trix");
SetIndexLabel(1,"Signal");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int i,limit;
int counted_bars=IndicatorCounted();
//---- check for possible errors
if(counted_bars<0) return(-1);
if(Bars<=Periodo) return(0);
//---- initial zero
if(counted_bars<1)
{
for(i=1;i<=Periodo;i++) TRIX_Buffer[Bars-i]=0.0;
for(i=1;i<=Periodo;i++) Signal_Buffer[Bars-i]=0.0;
for(i=1;i<=Periodo;i++) EMA1_buffer[Bars-i]=0.0;
for(i=1;i<=Periodo;i++) EMA2_buffer[Bars-i]=0.0;
for(i=1;i<=Periodo;i++) EMA3_buffer[Bars-i]=0.0;
}
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//---- Calculo el EMA1
for(i=0; i<limit; i++)
EMA1_buffer[i]=iMA(NULL,0,Periodo,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0; i<limit; i++)
EMA2_buffer[i]=iMAOnArray(EMA1_buffer,Bars,Periodo,0,MODE_EMA,i);
for(i=0; i<limit; i++)
EMA3_buffer[i]=iMAOnArray(EMA2_buffer,Bars,Periodo,0,MODE_EMA,i);
// for(i=0; i<limit; i++)
// TRIX_Buffer[i] = EMA3_buffer[i];
for(i=0; i<limit-1; i++)
TEMA_buffer[i] = 3 * EMA1_buffer[i] - 3 * EMA2_buffer[i] + EMA3_buffer[i];
for(i=0; i<limit-1; i++)
TRIX_Buffer[i] = (TEMA_buffer[i] - TEMA_buffer[i+1]) / TEMA_buffer[i+1] *100;
//TRIX_Buffer[i] = (EMA3_buffer[i] - EMA3_buffer[i+1]) / EMA3_buffer[i+1] *100;
//---- signal line counted in the 2-nd buffer
for(i=0; i<limit-1; i++)
Signal_Buffer[i]=iMAOnArray(TRIX_Buffer,Bars,Signal,0,MODE_SMA,i);
//---- done
return(0);
}
//+------------------------------------------------------------------+
Comments