This tool, titled TrendStrength, is designed to provide traders with a visual representation of market momentum and the prevailing strength of a price trend. Rather than looking at a single price point, it analyzes the relationship between various moving averages to determine how "stretched" or firm the current market movement is.
How the Logic Works
The indicator operates by comparing different layers of historical price data simultaneously. Here is a breakdown of the process:
- Multi-Layer Analysis: The script calculates ten different Exponential Moving Averages (EMAs) at once. These averages represent different time horizons, ranging from very short-term movements to longer-term trends.
- The Benchmark: It establishes a "baseline" using a very short 5-period moving average. This represents the most immediate price action available.
- Calculating the Gap: The logic then subtracts various longer-term averages (ranging from 10 periods up to 100 periods) from that primary short-term benchmark. By doing this, it identifies the distance between where the price is now and where the broader trend was.
- Cumulative Strength: Finally, the script adds all these differences together into a single value. This cumulative total is what you see plotted on your chart.
What This Means for the Trader
The resulting line serves as a "momentum gauge." Because it sums up the distances between many different moving averages:
- Trend Intensity: When the line moves significantly in one direction, it indicates that the current price is pulling away from its historical averages across multiple timeframes, suggesting a powerful and sustained trend.
- Market Equilibrium: When the line stays closer to the zero mark, it suggests that the short-term price action is aligned with the longer-term averages, often indicating a period of consolidation, stability, or a "flat" market.
- Visual Confirmation: By providing this in a separate window, the tool allows you to see the "health" of a trend independently of the price candles, helping you identify whether a move is gaining steam or losing its underlying strength.
//+------------------------------------------------------------------+
//| TrendStrength.mq4 |
//| Xaoc 2006 |
//| http://forex.xcd.ru/ |
//+------------------------------------------------------------------+
#property copyright "][aoc 2006"
#property link "http://forex.xcd.ru/"
//----
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_level1 0
//#property indicator_maximum 0.02
//#property indicator_minimum -0.02
double TS[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(1);
IndicatorShortName("TrendStrength");
SetIndexBuffer(0,TS);
SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 1, Orange);
SetIndexDrawBegin(0,2);
SetIndexLabel(0,"TS");
//---- indicators
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int mode, shift,counted_bars=IndicatorCounted();
//double ma40dbl;
double ma0, ma1, ma2, ma3, ma4, ma5, ma6, ma7, ma8, ma9, ma10, tmp;
//---- TODO: add your code here
//---- check for possible errors
if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
if(counted_bars>0) counted_bars--;
//limit=Bars-counted_bars;
//---- main loop
//---- main calculation loop
shift=Bars-1;
while(shift>=0)
{
mode=MODE_EMA;
tmp=iMA(NULL,0,5,0,mode,PRICE_WEIGHTED,shift);
ma1=tmp-iMA(NULL,0,10,0,mode,PRICE_WEIGHTED,shift);
ma2=tmp-iMA(NULL,0,20,0,mode,PRICE_WEIGHTED,shift);
ma3=tmp-iMA(NULL,0,30,0,mode,PRICE_WEIGHTED,shift);
ma4=tmp-iMA(NULL,0,40,0,mode,PRICE_WEIGHTED,shift);
ma5=tmp-iMA(NULL,0,50,0,mode,PRICE_WEIGHTED,shift);
ma6=tmp-iMA(NULL,0,60,0,mode,PRICE_WEIGHTED,shift);
ma7=tmp-iMA(NULL,0,70,0,mode,PRICE_WEIGHTED,shift);
ma8=tmp-iMA(NULL,0,80,0,mode,PRICE_WEIGHTED,shift);
ma9=tmp-iMA(NULL,0,90,0,mode,PRICE_WEIGHTED,shift);
ma10=tmp-iMA(NULL,0,100,0,mode,PRICE_WEIGHTED,shift);
//----
TS[shift]=ma1+ma2+ma3+ma4+ma5+ma6+ma7+ma8+ma9+ma10;
shift--;//
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments