Author: Douglas Lozada
TRIX_A

This tool is designed to help traders identify momentum and price trends by calculating a specific technical indicator known as the TRIX. Unlike standard indicators that look at raw price changes, this script processes the data through several layers of smoothing to filter out "market noise" and highlight more significant movements.

How the Logic Works

The script operates through a multi-step calculation process to create the visual data you see on your chart:

1. Multi-Layer Smoothing (The Foundation) Instead of calculating the trend directly from the price, the script performs three consecutive layers of "Exponential Moving Average" (EMA) calculations.

  • First, it calculates a moving average of the closing prices.
  • Second, it takes that result and calculates another moving average on top of it.
  • Third, it repeats this process one more time. By layering these averages, the script effectively "softens" the data, ensuring that minor, erratic price fluctuations do not trigger false signals.

2. Calculating Momentum (The TRIX Line) Once the three layers of smoothing are established, the script calculates the percentage change between the most recent smoothed value and the previous one. This represents the velocity or momentum of the price. This result is plotted as the primary "Trix" line on your screen.

3. The Signal Line To make the data easier to interpret, the script adds a secondary layer: a "Signal" line. This is a Simple Moving Average of the Trix line itself.

How to Read the Results

The primary goal of this logic is to provide a clear visual representation of market direction:

  • Trend Identification: When the Trix line moves upward, it suggests positive momentum; when it moves downward, it suggests negative momentum.
  • Confirmation: By comparing the Trix line against the Signal line, traders can look for points where the lines cross or diverge. These interactions often serve as visual cues to identify potential shifts in market direction or changes in the strength of a trend.

By using this "triple-smoothed" approach, the script aims to provide a more stable and reliable view of price movement than standard moving averages alone.

Indicators Used
Moving average indicatorMoving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
0 Downloads
0 Favorites
TRIX_A
//+------------------------------------------------------------------+
//| 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[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- 3 additional buffers are used for counting.
IndicatorBuffers(5);
SetIndexBuffer(2,EMA1_buffer);
SetIndexBuffer(3,EMA2_buffer);
SetIndexBuffer(4,EMA3_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++)
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