NRTR_v3
Download scriptThis tool is designed as a visual trend-tracking indicator for trading platforms, specifically engineered to identify the direction of price movement by filtering out minor market noise. It uses a logical framework that combines historical volatility with dynamic price action to determine whether the current market sentiment is bullish (upward) or bearish (downward).
Core Logic and Functionality
The script operates based on three primary layers of logic:
1. Volatility Measurement Before determining the trend, the tool calculates a "Dynamic Range" coefficient. It looks at a specific number of previous candles (defined by the user) to measure how much the price has been fluctuating between highs and lows. By calculating this average range, the tool establishes a "sensitivity threshold." This ensures that the indicator adapts to the current market environment—staying steady during low-volatility periods and reacting appropriately when the market becomes more active.
2. Trend Identification The tool scans the price history to establish the starting direction of the market. It looks at the relationship between opening and closing prices over a set period.
- If the price closed higher than it opened, the logic initiates an upward trend.
- If the price closed lower than it opened, it initiates a downward trend.
3. Dynamic Trend Maintenance Once a trend is established, the script follows the price movement while applying a "buffer zone" based on the volatility coefficient mentioned earlier. Instead of changing direction at every small price flicker, the logic requires the price to break significantly beyond its previous high or low relative to the average volatility.
- In an Upward Trend: The tool monitors for new highs. It will only switch the trend to "down" if the price drops below a specific calculated threshold.
- In a Downward Trend: The tool monitors for new lows. It will only switch the trend to "up" if the price rises above a specific calculated threshold.
Visual Output
The results are displayed on your chart as distinct visual markers:
- Blue Markers: Represent an active upward trend, indicating that the price is maintaining momentum above the established volatility buffer.
- Red Markers: Represent an active downward trend, indicating that the price is maintaining momentum below the established volatility buffer.
Summary for the User
Essentially, this script acts as a "smart filter." It looks at how much the market usually moves, calculates a safety zone based on that movement, and then places markers on your chart to show you the prevailing trend. It ignores small, insignificant price wiggles and only updates its signals when the price makes a significant move that confirms a change in market direction.
//+------------------------------------------------------------------+
//| NRTR.mq4 |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#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[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicator line
SetIndexBuffer(0, value1);
SetIndexBuffer(1, value2);
SetIndexStyle(0, DRAW_ARROW, EMPTY, 1);
SetIndexArrow(0, 159);
SetIndexStyle(1, DRAW_ARROW, EMPTY, 1);
SetIndexArrow(1, 159);
//---- name for DataWindow label
SetIndexLabel(0, "NRTRUp(" + IntegerToString(AveragePeriod) + ")");
SetIndexLabel(1, "NRTRDown(" + IntegerToString(AveragePeriod) + ")");
//----
if(CountBars > Bars)
CountBars = Bars;
SetIndexDrawBegin(0, Bars - CountBars + 1);
SetIndexDrawBegin(1, Bars - CountBars + 1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| NRTR |
//+------------------------------------------------------------------+
int start()
{
int i, counted_bars = IndicatorCounted();
double value;
double trend = 0, dK, AvgRange, price;
//----
if(Bars <= AveragePeriod)
return(0);
//---- initial zero
if(counted_bars < 1)
{
for(i = 1; i <= AveragePeriod; i++)
value1[Bars-i] = 0.0;
for(i = 1; i <= AveragePeriod; i++)
value2[Bars-i] = 0.0;
}
//----
AvgRange=0;
for(i = 1; i <= AveragePeriod; i++)
AvgRange += MathAbs(High[i] - Low[i]);
//----
if(Symbol() == "USDJPY" || Symbol() == "GBPJPY" || Symbol() == "EURJPY")
{
dK = (AvgRange / AveragePeriod) / 100;}
else
{
dK = AvgRange / AveragePeriod;
}
//----
if(Close[CountBars-1] > Open[CountBars-1])
{
value1[CountBars-1] = Close[CountBars-1] * (1 - dK);
trend = 1;
value2[CountBars-1] = 0.0;
}
//----
if(Close[CountBars-1] < Open[CountBars-1])
{
value2[CountBars-1] = Close[CountBars-1] * (1 + dK);
trend = -1;
value1[CountBars-1] = 0.0;
}
//----
i = CountBars - 1;
while(i >= 0)
{
value1[i] = 0;
value2[i] = 0;
if(trend >= 0)
{
if(Close[i] > price)
price = Close[i];
value = price * (1 - dK);
if(Close[i] < value)
{
price = Close[i];
value = price * (1 + dK);
trend = -1;
}
}
else
{
if(trend <= 0)
{
if(Close[i] < price)
price = Close[i];
value = price * (1 + dK);
if(Close[i] > value)
{
price = Close[i];
value = price * (1 - 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