This indicator is designed to help traders measure the strength and direction of a market trend by analyzing the relationship between current price action and multiple historical moving averages. Instead of just looking at where the price is going, it quantifies how aggressively the price is moving relative to its recent history.
How the Logic Works
The core logic operates by comparing the current closing price against six different Simple Moving Averages (SMA). Each of these moving averages is calculated using a specific "step" (defined by the PeriodStep setting). By looking at six different time horizons simultaneously, the tool can determine if the current price is consistently above or below the historical norms.
The calculation follows these steps:
- Comparison: For every candle on the chart, the script checks the current closing price against each of the six moving averages.
- Scoring System:
- If the current price is lower than a moving average, the script assigns a positive point to the score.
- If the current price is higher than a moving average, it assigns a negative point.
- Normalization: The total score from these six comparisons is then converted into a percentage-style value ranging from -100 to +100.
- A value of +100 indicates that the current price is significantly higher than all six historical averages (strong upward momentum).
- A value of -100 indicates the price is significantly lower than all six (strong downward momentum).
- Values near 0 suggest that the price is hovering around its moving averages, indicating a neutral or consolidating market.
Visual Representation
The indicator provides two distinct lines to help filter out market noise:
- The Value Line (Dotted): This represents the raw strength score calculated from the comparison logic described above. It reacts quickly to price changes.
- The Signal Line (Solid): To prevent the indicator from reacting too erratically to minor "wiggles" in the price, a smoothing calculation is applied to the Value Line. This creates a secondary signal line that helps identify more stable, sustained trend shifts rather than temporary spikes.
Key Settings for Customization
- PeriodStep: Determines how far back in time the moving averages look. A higher number looks at longer-term history.
- Slowing: Controls how much the signal line is smoothed. Increasing this value will make the signal line less reactive to sudden price jumps, providing a "steadier" view of the trend.
// Ñèëà òðåíäà.mq4
// Èíäèêàòîð
// Trend strength indicator
// Îïèñàíèå http://www.kroufr.ru/content/view/697/124/
// Èñïîëüçóåòñÿ ñðàâíåíèå öåíû ñ 6 SMA ñ øàãîì ïåðèîäà PeriodStep (ïî óìîë÷àíèþ 10) íà áîëüøå/ìåíüøå
// Çíà÷åíèÿ èäèêàòîðà: -100, -66,-33, 0, +33, +66, 100
// Êëàññ: îñöèëÿòîð
#property copyright "mandorr@gmail.com"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_minimum -120
#property indicator_maximum 120
extern int PeriodStep=10; // Øàã ïåðèîäà ñêîëüçÿùèõ
extern int Slowing=3; // Çàìåäëåíèå îñíîâíîé ëèíèè (ñèãíàëüíàÿ ëèíèÿ)
extern int CountBars=1000; // Êîëè÷åñòâî îòîáðàæàåìûõ áàðîâ
double buffer0[];
double buffer1[];
void init()
{
SetIndexStyle(0,DRAW_LINE,STYLE_DOT,1,Red);
SetIndexBuffer(0,buffer0);
SetIndexLabel(0,"Value");
SetIndexDrawBegin(0,0);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Red);
SetIndexBuffer(1,buffer1);
SetIndexLabel(1,"Signal");
SetIndexDrawBegin(1,0);
IndicatorShortName("Ñèëà òðåíäà ("+PeriodStep+","+Slowing+")");
}
void start()
{
int value;
int step=1; if (PeriodStep>1) step=PeriodStep;
double x0, x1, x2, x3, x4, x5, x6;
for (int i=0; i<=CountBars-1; i++)
{
x0=Close[i];
x1=iMA(NULL,0,1*step,0,MODE_SMA,PRICE_CLOSE,i);
x2=iMA(NULL,0,2*step,0,MODE_SMA,PRICE_CLOSE,i);
x3=iMA(NULL,0,3*step,0,MODE_SMA,PRICE_CLOSE,i);
x4=iMA(NULL,0,4*step,0,MODE_SMA,PRICE_CLOSE,i);
x5=iMA(NULL,0,5*step,0,MODE_SMA,PRICE_CLOSE,i);
x6=iMA(NULL,0,6*step,0,MODE_SMA,PRICE_CLOSE,i);
value=0;
if (x1<x0) value++;
if (x2<x0) value++;
if (x3<x0) value++;
if (x4<x0) value++;
if (x5<x0) value++;
if (x6<x0) value++;
if (x1>x0) value--;
if (x2>x0) value--;
if (x3>x0) value--;
if (x4>x0) value--;
if (x5>x0) value--;
if (x6>x0) value--;
buffer0[i]=100*value/6;
}
for (i=0; i<=CountBars-1; i++)
{
buffer1[i]=iMAOnArray(buffer0,0,Slowing,0,MODE_SMA,i);
}
}
Comments