This tool is a technical analysis indicator designed for the MetaTrader platform to help traders identify momentum and potential trend reversals in the financial markets. It works by analyzing price history through multiple layers of smoothing to filter out "market noise" and provide a clearer picture of where the market is heading.
How the Logic Works
The script follows a sophisticated three-step process to calculate its data:
1. Multi-Layer Smoothing Instead of looking at raw, volatile price movements, the tool applies several layers of Exponential Moving Averages (EMA). By layering these averages on top of one another, the script isolates the underlying trend of the asset. It effectively "flattens" out sudden, insignificant price spikes so that the trader can focus on the primary direction of the market.
2. Rate of Change Calculation Once the smoothed data is established, the tool calculates the percentage change between these moving averages. This transformation allows the user to see the momentum—specifically how fast the trend is accelerating or decelerating. A rising value indicates strengthening upward momentum, while a falling value suggests downward pressure.
3. Signal Generation (The "Cross" Logic) The core utility of this script lies in its ability to generate visual and audio signals based on the relationship between two main lines:
- The Main TRIX Line: Represents the primary momentum.
- The Signal Line: A secondary, slower moving average of the TRIX line.
When these two lines cross each other, it often suggests a shift in market sentiment. The script is programmed to detect these specific "crossover" points:
- Bullish Sentiment: When the signal line moves from above to below the main line, it may indicate upward momentum is gaining strength.
- Bearish Sentiment: When the signal line moves from below to above the main line, it may indicate downward momentum is increasing.
User Experience Features
To make these insights actionable for a live trader, the script includes several automated features:
- Visual Cues: The indicator plots distinct arrows on the chart to highlight exactly where these crossovers occur, removing the guesswork from interpreting the lines.
- Audio Alerts: The script is configured to play an alert sound ("alert.wav") the moment a crossover happens on the current candle. This allows traders to react quickly to market changes without having to stare at the screen constantly.
- Customizable Sensitivity: Users can adjust the "Period" and "Signal Period" settings to make the indicator more responsive to fast price movements or more stable for long-term trend following.
//+------------------------------------------------------------------+
//| TRIX.mq4 |
//| by Raff |
//| |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, raff1410@o2.pl"
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Gold
#property indicator_color3 Green
#property indicator_color4 Red
#property indicator_level1 0
//---- indicator parameters
extern int TRIX_Period = 18;
extern int Signal_Period = 5;
extern bool Signals = true;
int CountBars = 1000;
//---- indicator buffers
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
double ind_buffer5[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
IndicatorBuffers(5);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_ARROW);
SetIndexArrow(2,233);
SetIndexStyle(3,DRAW_ARROW);
SetIndexArrow(3,234);
SetIndexDrawBegin(0,4*TRIX_Period);
SetIndexDrawBegin(1,4*TRIX_Period);
SetIndexDrawBegin(2,4*TRIX_Period);
SetIndexDrawBegin(3,4*TRIX_Period);
//---- indicator buffers mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
SetIndexBuffer(3,ind_buffer4);
SetIndexBuffer(4,ind_buffer5);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("TRIX index | Period: "+TRIX_Period+", Signal Period: "+Signal_Period+" | ");
SetIndexLabel(0,"TRIX");
SetIndexLabel(1,"Signal");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| TRIX |
//+------------------------------------------------------------------+
int start()
{
int i, counted_bars=IndicatorCounted();
//---- trix
for(i=0; i<Bars; i++) ind_buffer1[i]=iMA(NULL,0,TRIX_Period,0,MODE_EMA,PRICE_CLOSE,i);
for(i=0; i<Bars; i++) ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,TRIX_Period,0,MODE_EMA,i);
for(i=0; i<Bars; i++) ind_buffer5[i]=iMAOnArray(ind_buffer2,Bars,TRIX_Period,0,MODE_EMA,i);
i=Bars-2;
while(i>=0)
{
ind_buffer1[i]=(ind_buffer5[i]-ind_buffer5[i+1])/ind_buffer5[i+1];
i--;
}
for(i=0; i<Bars; i++) ind_buffer2[i]=iMAOnArray(ind_buffer1,Bars,Signal_Period,0,MODE_EMA,i);
//---- signals
i=Bars-4*TRIX_Period;
while(i>=0)
{
if (Signals==true)
{
if (ind_buffer2[i]<ind_buffer1[i] && ind_buffer2[i+1]>=ind_buffer1[i+1]) ind_buffer3[i]=ind_buffer2[i]-0.0005;
if (ind_buffer2[i]>ind_buffer1[i] && ind_buffer2[i+1]<=ind_buffer1[i+1]) ind_buffer4[i]=ind_buffer2[i]+0.0005;
if (ind_buffer3[0]==ind_buffer3[i] || ind_buffer4[0]==ind_buffer4[i]) PlaySound("alert.wav");
}
i--;
}
//---- done
return(0);
}
Comments