Overview of the Simple Trend Detector
The Simple Trend Detector is a specialized visual tool designed to help traders identify the prevailing direction of the market. Instead of just showing you the price movement, it analyzes the relationship between "buying" and "selling" pressures over a specific period to provide a clearer picture of whether the current momentum is leaning toward the upside or the downside.
How the Logic Works
The script operates by breaking down every price candle into two distinct components: gains (positive movements) and losses (negative movements). Here is the step-by-step logic it follows:
1. Measuring Individual Price Action For every candle on your chart, the indicator looks at the difference between the opening price and the closing price. If the price went up, it captures that gain as a "positive" value; if it went down, it captures that loss as a "negative" value.
2. Weighting Recent Activity The tool does not treat all past data equally. It uses a weighted calculation system where more recent price actions are given more importance than older ones. This ensures that the indicator reacts quickly to current market changes while still considering the context of what happened just before it.
3. Calculating the Trend Ratio Once the positive and negative movements are identified and weighted, the script combines them to create a ratio. This ratio determines the "Trend Score."
- If the market is dominated by upward movement, the score moves closer to the top of the indicator window (1.0).
- If the market is dominated by downward movement, the score moves toward the bottom (0.0).
- If there is an equal balance between buying and selling pressure, the score settles in the middle (0.5).
Visual Interpretation
The indicator appears in a separate window below your main price chart. It provides a smooth line that oscillates between 0 and 1:
- Above 0.7: Suggests strong bullish momentum (the market is trending upward significantly).
- Below 0.3: Suggests strong bearish momentum (the market is trending downward significantly).
- Near 0.5: Indicates a neutral zone where the market may be consolidating or moving sideways with no clear trend.
By observing this line, traders can better visualize whether the "weight" of the market is currently leaning in their favor or against them, helping to filter out minor price noise.
//The Simple Trend Detector. Based on code RSI.mq4, Copyright © 2004, MetaQuotes Software Corp. http://www.metaquotes.net/
#property copyright "Copyright © 2004, MetaQuotes Software Corp., BECEMAL 2010"
#property link "http://www.becemal.ru/"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 1
#property indicator_level1 0.3
#property indicator_level2 0.7
#property indicator_buffers 3
#property indicator_color1 RoyalBlue
extern int STDPeriod=15;
double Buffer[];
double PosBuffer[];
double NegBuffer[];
int init()
{
string short_name = "STD("+STDPeriod+")";
SetIndexBuffer(1,PosBuffer);
SetIndexBuffer(2,NegBuffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_NONE);
SetIndexStyle(2,DRAW_NONE);
SetIndexBuffer(0,Buffer);
IndicatorShortName(short_name);
SetIndexLabel(0,"STD");
SetIndexDrawBegin(0,STDPeriod);
PosBuffer[-1]=0;
NegBuffer[-1]=0;
PosBuffer[0]=0;
NegBuffer[0]=0;
return(0);
}
int start()
{
int i, ii, counted_bars = IndicatorCounted();
double rel, negative, positive, Den;
if(Bars<=STDPeriod) return(0);
if(counted_bars<1)
for(i=1;i<=STDPeriod;i++) Buffer[Bars-i]=0.5;
i=Bars-STDPeriod-1;
if(counted_bars>=STDPeriod) i=Bars-counted_bars-1;
ii = i;
while(i >= 0) {
positive = 0.0; negative = 0.0;
rel=Close[i] - Open[i];
if(rel>0) positive = rel;
else negative =-rel;
PosBuffer[i] = positive;
NegBuffer[i] = negative;
i--;
}
i = ii;
while(i >= 0) {
positive = 0.0; negative = 0.0;
for(int j = 0;j < STDPeriod;j++) {
double Norm = STDPeriod - j + 1;
positive += Norm * PosBuffer[i+j];
negative += Norm * NegBuffer[i+j]; }
Den = positive + negative;
if(Den == 0.0) Buffer[i] = 1.0;
else Buffer[i]= positive / Den;
i--;
}
return(0);
}
Comments