Trend strength index - Hassler
Download scriptHow the Trend Strength Index Works
The Trend Strength Index is a technical analysis tool designed to help traders visualize the momentum and power of current market movements. Rather than simply showing you which direction the price is moving, this indicator focuses on how "strong" or "persistent" that movement actually is by filtering out market noise.
Here is a step-by-step breakdown of the logic used to calculate these values:
1. Measuring Raw Movement
The process begins by looking at the price change over a specific window of time (defined by the Ratio Period). The script calculates the distance between the current price and the price from several bars ago. To ensure that this measurement isn't distorted by sudden, tiny flickers in price, it divides that distance by the Average True Range (ATR). This step essentially "normalizes" the data, making it easier to see significant trend moves regardless of whether the market is currently very volatile or very calm.
2. Smoothing the Data
Because raw price movements can be jagged and erratic, the script takes the normalized values from the first step and applies a Short Average. This acts as a first layer of smoothing, removing minor fluctuations and highlighting the immediate trend direction.
3. Identifying the Final Trend Strength
To provide a stable and readable signal for the trader, the script then applies a second, much longer Long Average to the previously smoothed data. This final calculation creates the "Trend Strength Index" line you see on your chart.
By layering these three calculations—measuring normalized movement, applying a short-term smooth, and finishing with a long-term smooth—the indicator provides a refined view of market dynamics. It helps identify periods where a trend is gaining significant power versus periods where the market is moving sideways or lacking conviction.
//+------------------------------------------------------------------+
//| Trend Strength Index |
//| coded by mladen |
//| |
//| The creator of of this version of Trend Strength Index }
//| is Frank Hassler in cooperation with David Varadi |
//+------------------------------------------------------------------+
#property copyright "mladen"
#property link "mladenfx@gmail.com"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
#property indicator_width1 2
//
//
//
//
//
extern int ShortAveragePeriod = 10;
extern int ShortAverageMethod = MODE_SMA;
extern int LongAveragePeriod = 100;
extern int LongAverageMethod = MODE_SMA;
extern int RatioPeriod = 10;
//
//
//
//
//
double tsiBuffer[];
double rawBuffer1[];
double rawBuffer2[];
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
//
//
//
//
//
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0,tsiBuffer); SetIndexLabel(0,"Trend strength index");
SetIndexBuffer(1,rawBuffer1);
SetIndexBuffer(2,rawBuffer2);
IndicatorShortName("Trend strength index ("+ShortAveragePeriod+","+LongAveragePeriod+")");
return(0);
}
//
//
//
//
//
int start()
{
int counted_bars=IndicatorCounted();
int i,limit;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit = MathMin(Bars-counted_bars,Bars-1);
//
//
//
//
//
for (i=limit; i>=0; i--)
{
double atr = iATR(NULL,0,RatioPeriod,i);
if (atr!=0)
rawBuffer1[i] = MathAbs(Close[i]-Close[i+RatioPeriod])/atr;
else rawBuffer1[i] = 0;
}
for (i=limit; i>=0; i--) rawBuffer2[i] = iMAOnArray(rawBuffer1,0,ShortAveragePeriod,0,ShortAverageMethod,i);
for (i=limit; i>=0; i--) tsiBuffer[i] = iMAOnArray(rawBuffer2,0,LongAveragePeriod,0,LongAverageMethod,i);
return(0);
}
Comments