_Trix
Download scriptThis script is designed as a technical analysis tool for MetaTrader, specifically intended to help traders identify trends and momentum in financial markets. It functions by creating a specialized visual indicator that calculates the rate of change within a price series using a triple-smoothing process.
How the Logic Works
The core objective of this script is to "smooth out" market noise to reveal the underlying trend more clearly. Instead of looking at raw, volatile price movements, the tool processes the data through three consecutive layers of calculation:
1. The Initial Smoothing Layer The tool begins by taking the average price of the market over a specific period (defined by the "Depth" setting). By using an Exponential Moving Average, it gives more weight to recent prices, ensuring the tool remains responsive to current market conditions while filtering out minor fluctuations.
2. The Double and Triple Smoothing Layers The unique strength of this logic lies in its repetition. The script takes the result of the first average and calculates a second average on top of it. It then takes that second result and performs a third averaging process. By layering these three calculations, the tool creates a highly refined data point that represents a very stable view of the market's direction, effectively stripping away most of the "jitter" found in standard price charts.
3. The Momentum Calculation Once the triple-smoothed data is established, the script performs a final calculation to determine the percentage change between the current value and the previous one. This converts the smoothed data into a momentum oscillator.
Visual Interpretation
Rather than appearing on the main price chart (like a candle or a line showing the price), this indicator lives in its own separate window at the bottom of your screen. It provides a visual representation of how fast the price trend is accelerating or decelerating:
- Trend Strength: The smoother the line, the more stable the underlying trend.
- Momentum Shifts: By looking at the percentage change provided by the final calculation, traders can see if the momentum is gaining strength, losing steam, or reversing direction.
In summary, this script acts as a sophisticated filter. It takes raw market data, subjects it to three layers of mathematical smoothing to remove noise, and then calculates the resulting percentage move to provide a clear picture of market momentum.
//+------------------------------------------------------------------+
//| Trix.mq4 |
//| Copyright © 2006, systrad5 |
//| 17/09/06 |
//| Feedback or comments welcome at systrad5@yahoo.com |
//+------------------------------------------------------------------+
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int Depth = 16;
//---- buffers
double TrixBuf[];
double T1Buf[];
double T2Buf[];
double T3Buf[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(4);
//---- additional buffers
SetIndexStyle(0, DRAW_LINE);
SetIndexBuffer(0, TrixBuf);
SetIndexBuffer(1, T1Buf);
SetIndexBuffer(2, T2Buf);
SetIndexBuffer(3, T3Buf);
//---- name for DataWindow and indicator subwindow label
string short_name = "Trix(" + Depth + ")";
IndicatorShortName(short_name);
SetIndexLabel(0, short_name);
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int start()
{
int i;
//----
if(Bars <= Depth + 10)
return(0);
//---- last counted bar will be recounted
int counted_bars = IndicatorCounted();
int limit = Bars - counted_bars;
if(counted_bars > 0)
limit++;
//-- The Trix Calc
for(i = limit; i >= 0; i--)
T1Buf[i] = iMA(NULL, 0, Depth, 0, MODE_EMA, PRICE_TYPICAL, i);
//----
for(i = limit; i >= 0; i--)
T2Buf[i] = iMAOnArray(T1Buf, 0, Depth, 0, MODE_EMA, i);
//----
for(i = limit; i >= 0; i--)
T3Buf[i] = iMAOnArray(T2Buf, 0, Depth, 0, MODE_EMA, i);
//----
for(i = limit; i >= 0; i--)
{
if(T3Buf[i+1] != 0)
TrixBuf[i] = ((T3Buf[i] - T3Buf[i+1]) / T3Buf[i+1])*100;
}
return(0);
}
//+------------------------------------------------------------------+
Comments