This technical indicator is designed to provide a smoothed, visual representation of price momentum by analyzing the underlying rate of change in an asset's value. Unlike standard indicators that plot directly against the raw price, this script applies a sophisticated multi-layer smoothing process to help traders identify significant trends and shifts in market behavior.
Core Logic and Methodology
The indicator operates through three primary logical stages:
1. Logarithmic Transformation Instead of using the literal price of an asset, the tool first applies a logarithmic calculation to the moving average of the closing prices. By converting prices into a logarithmic scale, the indicator becomes less sensitive to extreme price spikes and more focused on the proportional percentage changes. This is particularly useful for analyzing assets that experience large fluctuations over long periods.
2. Triple Exponential Smoothing (Trix) The script then processes these logarithmic values through three successive layers of exponential moving averages. Each layer acts as a filter:
- The first layer smooths out the initial price noise.
- The second layer smooths the results of the first.
- The third layer smooths the results of the second.
By nesting these averages, the indicator effectively filters out "market noise" and minor fluctuations, leaving behind a much clearer picture of the underlying trend. This specific sequence is known as the Trix calculation, which is highly regarded for its ability to highlight momentum shifts.
3. Momentum Measurement and Scaling In the final step, the script calculates the difference between the most recent smoothed value and the previous one. It then multiplies this difference by a factor of 10,000 to magnify the result into a readable format on your chart.
Visual Interpretation
The resulting output appears in a separate window below your main price chart. The primary line represents the momentum of the price:
- Trend Direction: When the line moves upward, it suggests increasing bullish momentum; when it moves downward, it indicates bearish momentum.
- Zero Line Interaction: The indicator includes a reference point at zero. Crossing above or below this zero level can be interpreted as a significant shift in the trend direction, signaling a transition from one market sentiment to another.
//+------------------------------------------------------------------+
//| Trix of log of a price.mq4 |
//| |
//+------------------------------------------------------------------+
#property copyright "copyleft mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 DimGray
#property indicator_color2 DarkOrange
#property indicator_style1 STYLE_DOT
//
//
//
//
//
extern int TrixPeriod = 9;
extern int TrixPrice = PRICE_CLOSE;
//
//
//
//
//
double TrixBuffer[];
double ZeroBuffer[];
double EmaBuffer1[];
double EmaBuffer2[];
double EmaBuffer3[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0,ZeroBuffer);
SetIndexBuffer(1,TrixBuffer);
SetIndexBuffer(2,EmaBuffer1);
SetIndexBuffer(3,EmaBuffer2);
SetIndexBuffer(4,EmaBuffer3);
IndicatorShortName("Trix ("+TrixPeriod+")");
return(0);
}
//
//
//
//
//
int start()
{
double alpha = 2.0/(1.0+TrixPeriod);
int counted_bars=IndicatorCounted();
if(counted_bars < 0) return(-1);
if(counted_bars>0) counted_bars--;
int limit = Bars-counted_bars;
//
//
//
//
//
for(int i=limit; i>=0; i--)
{
double price = MathLog(iMA(NULL,0,1,0,MODE_SMA,TrixPrice,i));
EmaBuffer1[i] = EmaBuffer1[i+1]+alpha*(price -EmaBuffer1[i+1]);
EmaBuffer2[i] = EmaBuffer2[i+1]+alpha*(EmaBuffer1[i]-EmaBuffer2[i+1]);
EmaBuffer3[i] = EmaBuffer3[i+1]+alpha*(EmaBuffer2[i]-EmaBuffer3[i+1]);
TrixBuffer[i] = (EmaBuffer3[i]-EmaBuffer3[i+1])*10000;
ZeroBuffer[i] = 0;
}
return(0);
}
Comments