NRTR_Line1
Download scriptThe NRTR Line is a specialized technical analysis tool designed to help traders identify the prevailing direction of a market and visualize potential trend reversals. Unlike standard moving averages that simply smooth out price data, this indicator focuses on the "range" or volatility of the market to determine when a trend has lost its momentum and is likely to shift.
How the Logic Works
The script operates by analyzing two primary components: Volatility (Average Range) and Price Action Trends.
1. Measuring Market Volatility Instead of looking only at the closing price, the tool calculates the average range of the market over a specific period (user-defined by the AveragePeriod setting). It looks at the distance between the high and low prices for each candle, adds the current spread, and averages these values. This creates a dynamic "buffer" or distance that represents how much the price is currently swinging.
2. Establishing the Trend Direction The tool tracks the price movement to determine if the market is in an upward or downward state:
- Uptrend: The logic follows the price as it makes new highs. It creates a "boundary" line just below the current price based on the calculated average range.
- Downtrend: The logic follows the price as it makes new lows. It creates a "boundary" line just above the current price based on the average range.
3. Detecting Reversals The core intelligence of the script lies in its reaction to "overshoots."
- If the market is in an Uptrend, but the price falls below the calculated boundary (the price minus the average range), the script recognizes that the upward momentum has broken. It then switches the trend to "Down" and flips the boundary line to sit above the price.
- Conversely, if the market is in a Downtrend and the price pushes above the upper boundary (the price plus the average range), the script identifies a break in downward momentum and switches the trend back to "Up."
Visual Representation
The indicator displays two distinct lines on your chart:
- One line represents the current Uptrend boundary (displayed in Aqua).
- The other line represents the current Downtrend boundary (displayed in Magenta).
By watching these lines, a trader can see the "ceiling" or "floor" of the current movement. When the price interacts with these lines and triggers a trend switch, it provides a visual signal that the market's dominant direction may be changing.
//+------------------------------------------------------------------+
//| NRTR Line.mq4 |
//| Copyright © 2006, Nick Bilak |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Nick Bilak"
//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Magenta
//---- indicator parameters
extern int AveragePeriod=21;
//---- indicator buffers
double e1[];
double e2[];
int i,bar,trend=1;
double value,price,dK,AvgRange;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_LINE);
SetIndexStyle(1,DRAW_LINE);
SetIndexEmptyValue(0,0);
SetIndexEmptyValue(1,0);
if(
!SetIndexBuffer(0,e1) ||
!SetIndexBuffer(1,e2)
)
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("NRTR_Line("+AveragePeriod+")");
//---- initialization done
return(0);
}
int start() {
int counted_bars=IndicatorCounted();
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
int limit=Bars-20-counted_bars;
double spread=Ask-Bid;
double ap;
ap=AveragePeriod;
for(bar=limit; bar>=0; bar--) {
e1[bar]=0; e2[bar]=0;
AvgRange=0;
for (i=bar; i<bar+AveragePeriod; i++) {
AvgRange=AvgRange+MathAbs(spread+High[bar]-Low[bar]);
}
dK = AvgRange/ap;
if (Close[bar]>10) dK=dK/100.0;
if (trend == 1) {
if (Close[bar] > price) price = Close[bar];
value = price - dK;
if (Close[bar] < value) {
price = Close[bar];
value = price + dK;
trend = -1;
}
}
if (trend == -1) {
if (Close[bar] < price) price = Close[bar];
value = price + dK;
if (Close[bar] > value) {
price = Close[bar];
value = price - dK;
trend = 1;
}
}
if (trend == -1) e1[bar]=value; //SetIndexValue(bar, value);
if (trend == 1) e2[bar]=value; //SetIndexValue2(bar, value);
}
}
Comments