This tool is designed to help traders visualize market momentum by identifying and highlighting the prevailing direction of price movement on a chart. Rather than just showing raw price action, it filters out minor "noise" to focus on the significant trends.
How the Logic Works
The script operates by calculating a dynamic volatility measure based on a user-defined period of past price activity. It looks at the high and low points of the candles within this timeframe to determine how much the market is moving. This measurement serves as a "buffer" or "threshold" that determines how significant a price move must be to actually change the trend direction.
Trend Tracking and Detection
The core logic functions like a state machine that monitors whether the market is currently in an upward or downward phase:
- Upward Momentum: When the price moves significantly higher, the tool confirms an bullish trend. It tracks the highest point reached and projects a boundary slightly below it based on the calculated volatility.
- Downward Momentum: Conversely, when the price drops significantly, the tool confirms a bearish trend, tracking the lowest point and projecting a boundary slightly above it.
Signal Generation
The script uses these boundaries to filter out "fakeouts." A trend only reverses when the price penetrates the established threshold of the opposing direction.
On your chart, this is represented visually by two distinct markers:
- Bullish Signals: When the logic identifies an upward move that exceeds the volatility buffer, it marks the position in one color (Blue).
- Bearish Signals: When the price breaks through the threshold to the downside, it marks the position in a different color (Red).
By using this approach, the tool helps traders stay on the right side of the market by identifying when a trend is strong enough to be considered meaningful, rather than reacting to every small fluctuation in price.
//+------------------------------------------------------------------+
//| NRTR.mq4 |
//| Nick Bilak |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int AveragePeriod=10;
extern int CountBars=300;
//---- buffers
double value1[];
double value2[];
int trend=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexStyle(1,DRAW_ARROW);
SetIndexArrow(1,159);
SetIndexBuffer(0,value1);
SetIndexBuffer(1,value2);
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| NRTR |
//+------------------------------------------------------------------+
int start()
{
if (CountBars>Bars) CountBars=Bars;
SetIndexDrawBegin(0,Bars-CountBars+1);
SetIndexDrawBegin(1,Bars-CountBars+1);
int i,j,counted_bars=IndicatorCounted();
double value;
double dK,ap,AvgRange,price;
ap=AveragePeriod;
//----
if(Bars<=AveragePeriod) return(0);
i=CountBars-1;
while(i>=0) {
value1[i]=0; value2[i]=0;
AvgRange=0;
for (j=i ; j<i+AveragePeriod; j++)
AvgRange += MathAbs((Ask-Bid)+High[j]-Low[j]);
dK = AvgRange/ap;
if (Close[i]>10) dK=dK/100.0;
if (trend >= 0) {
if (Close[i] > price) {
price = Close[i];
value = price - dK;
trend=1;
}
if (Close[i] < value) {
price = Close[i];
value = price + dK;
trend = -1;
}
}
else if (trend <= 0) {
if (Close[i] < price) {
price = Close[i];
value = price + dK;
trend=-1;
}
if (Close[i] > value) {
price = Close[i];
value = price - dK;
trend = 1;
}
}
if (trend == 1) {value1[i]=value; value2[i]=0.0;}
if (trend == -1) {value2[i]=value; value1[i]=0.0;}
i--;
}
return(0);
}
Comments