NRTR_v2
Download scriptThis script functions as a visual trading indicator designed to identify and plot market trends by tracking price momentum and volatility. It works by analyzing historical price movements to determine whether the current market direction is bullish (upward) or bearish (downward).
Core Logic Overview
The tool operates based on two primary metrics: the recent price history and the relative "range" of the candles (the distance between the highest and lowest prices over a specific number of bars). By combining these, the script calculates a dynamic threshold used to decide when a trend has shifted.
How it Works
- Volatility Calculation: The script first looks at a user-defined period (defaulting to 10 bars) to measure the average range of price movement. This helps the indicator understand how much "room" the price usually moves in during normal market conditions.
- Currency Adjustments: The logic includes an automatic adjustment for specific currency pairs (USDJPY, GBPJPY, and EURJPY). Because these pairs often have different price scales compared to others, the script modifies its calculation to ensure the indicator remains accurate and consistent across different markets.
- Trend Identification: The script scans the chart starting from a set point in the past and moves toward the present. It looks for specific "breakout" behaviors:
- Upward Trend: If the price is moving higher and stays above its calculated threshold, it marks a bullish trend.
- Downward Trend: If the price drops below its calculated threshold, it signals a shift to a bearish trend.
- Dynamic Price Tracking: Rather than just looking at the current candle in isolation, the script "remembers" the price levels as it moves through history. It tracks whether the price is breaking new highs or lows relative to the previous movement, allowing it to flip the trend status instantly when a significant reversal occurs.
Visual Representation
The result of this logic is displayed on your chart as directional arrows:
- Blue Arrows: Indicate periods where the logic has identified an upward trend.
- Red Arrows: Indicate periods where the logic has identified a downward trend.
By filtering out minor "noise" in the price action and focusing on these structural shifts, the indicator aims to provide a clearer picture of the prevailing 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(" + AveragePeriod + ")");
SetIndexLabel(1, "NRTRDown(" + 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