NRTR Pilot Alert_v1
Download scriptThe NRTR indicator is designed to help traders identify market trends and visualize potential Stop Loss (S/L) levels by analyzing price movements over a specific period. It works by calculating the "volatility" of the market—essentially measuring how much price typically moves between its highs and lows—and using that data to project support and resistance points on your chart.
Core Logic and Methodology
1. Volatility Calculation The script first looks at a user-defined window of historical bars (the Average Period). It calculates the average range of these candles to determine a "Dynamic Constant" (dK). This constant represents the typical price fluctuation, ensuring that the projected levels adapt automatically as market conditions become more or less volatile.
2. Trend Identification The indicator operates in two distinct modes depending on how you prefer to view price action:
- Opening/Closing Mode: By default, the script looks at the relationship between the opening and closing prices of the candles. It identifies whether the market is pushing upward or downward based on these "body" movements.
- High/Low (HL) Mode: Alternatively, it can be configured to ignore the candle bodies and focus solely on the absolute highs and lows. This mode tracks the midpoint of the price range, which is often useful for identifying the "center of gravity" in a trade.
3. Dynamic Level Projection Once a trend is established (either Bullish or Bearish), the script projects a specific value based on the calculated volatility:
- In an uptrend, it calculates a price level slightly below the current price action to act as a potential floor.
- In a downtrend, it calculates a price level slightly above the current price action to act as a potential ceiling.
As new price data arrives, the script constantly monitors for "breakouts." If the price moves significantly enough to cross these projected levels in the opposite direction, the indicator flips the trend and projects a new level immediately.
4. Visual Representation and Alerts The logic translates these calculations into visual markers on your chart. Rather than just drawing lines, it places specific signals that represent the current Stop Loss values for both "Buy" and "Sell" scenarios.
To ensure you don't miss critical shifts, the script includes an automated notification system. It monitors for changes in these levels; whenever a trend reversal occurs and a new level is calculated, the indicator can trigger a visual alert to notify you of the updated price structure in real-time.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| NRTR.mq4 |
//| Copyright © 2005, VG many thanks to Konkop and dupidu |
//| 4vg@mail.ru |
//+------------------------------------------------------------------+
#property copyright "VG many thanks to Konkop and dupidu"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Magenta
#property indicator_color4 Yellow
double ind_buffer1[];
double ind_buffer2[];
double ind_buffer3[];
double ind_buffer4[];
extern double AveragePeriod = 40;
extern bool OCnotAverage = true;
extern int MaxBarsToCount = 200;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1);
SetIndexDrawBegin(0,AveragePeriod);
SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1);
SetIndexDrawBegin(1,AveragePeriod);
SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,3);
SetIndexDrawBegin(2,AveragePeriod);
SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,3);
SetIndexDrawBegin(3,AveragePeriod);
//---- indicator buffers mapping
if(!SetIndexBuffer(0,ind_buffer1) && !SetIndexBuffer(1,ind_buffer2)
&& !SetIndexBuffer(2,ind_buffer3)&& !SetIndexBuffer(3,ind_buffer4))
Print("cannot set indicator buffers!");
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("NRTR");
SetIndexLabel(0,"Sell S/L");
SetIndexLabel(1,"Buy S/L");
SetIndexLabel(2,"Sell S/L");
SetIndexLabel(3,"Buy S/L");
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int bar, limit, PrevAlertTime;
double value = 0;
double price = 0;
double trend, dK, AvgRange, HLTrend;
//---- TODO: add your code here
if(Bars<=MaxBarsToCount) return(-1);
for (int shift=MaxBarsToCount; shift>=0; shift--)
{
ind_buffer1[shift]=0;
ind_buffer2[shift]=0;
ind_buffer3[shift]=0;
ind_buffer4[shift]=0;
}
AvgRange=0;
for (int i=1; i<=AveragePeriod; i++) AvgRange+= MathAbs(High[i]-Low[i]);
dK = AvgRange/AveragePeriod/Point/10000;
if (OCnotAverage)
{
if (Close[MaxBarsToCount] > Open[MaxBarsToCount])
{
value = Close[MaxBarsToCount] * (1 - dK);
trend = 1;
ind_buffer2[MaxBarsToCount] = value;
}
if (Close[MaxBarsToCount] < Open[MaxBarsToCount])
{
value = Close[MaxBarsToCount] * (1 + dK);
trend = -1;
ind_buffer1[MaxBarsToCount] = value;
}
for (bar = MaxBarsToCount - 1; bar >= 0; bar--)
{
if (trend >= 0)
{
if (Low[bar] > price) price = Close[bar];
value = price * (1 - dK);
if (Close[bar] < value)
{
price = Close[bar];
value = price * (1 + dK);
trend = -1;
}
}
else
if (trend <= 0)
{
if (High[bar] < price) price = Close[bar];
value = price * (1 + dK);
if (Close[bar] > value)
{
price = Close[bar];
value = price * (1 - dK);
trend = 1;
}
}
if (trend == -1) ind_buffer1[bar] = value;
if (trend == 1) ind_buffer2[bar] = value;
}
if (CurTime() - PrevAlertTime > Period()*60)
{
if ((ind_buffer1[0] != ind_buffer1[1]) || (ind_buffer2[0] != ind_buffer2[1]))
{
Alert("Íîâûé S/L íà ",value);
PrevAlertTime = CurTime();
}
}
}
else
{
if ((High[MaxBarsToCount] + Low[MaxBarsToCount])/2 > (High[MaxBarsToCount-1] + Low[MaxBarsToCount-1])/2)
{
value = (High[MaxBarsToCount] + Low[MaxBarsToCount])/2 * (1 - dK);
HLTrend = 1;
ind_buffer4[MaxBarsToCount] = value;
}
else
{
value = (High[MaxBarsToCount] + Low[MaxBarsToCount])/2 * (1 + dK);
HLTrend = -1;
ind_buffer3[MaxBarsToCount] = value;
}
for (bar = MaxBarsToCount - 1; bar >= 0; bar--)
{
if (HLTrend >= 0)
{
if (Low[bar] > price) price = (High[bar] + Low[bar])/2;
value = price * (1 - dK);
if ((High[bar] + Low[bar])/2 < value)
{
price = (High[bar] + Low[bar])/2;
value = price * (1 + dK);
HLTrend = -1;
}
}
else
if (HLTrend <= 0)
{
if (High[bar] < price) price = (High[bar] + Low[bar])/2;
value = price * (1 + dK);
if ((High[bar] + Low[bar])/2 > value)
{
price = (High[bar] + Low[bar])/2;
value = price * (1 - dK);
HLTrend = 1;
}
}
if (HLTrend == -1) ind_buffer3[bar] = value;
if (HLTrend == 1) ind_buffer4[bar] = value;
}
if (CurTime() - PrevAlertTime > Period()*60)
{
if ((ind_buffer3[0] != ind_buffer3[1]) || (ind_buffer4[0] != ind_buffer4[1]))
{
Alert("Íîâûé S/L íà ",value);
PrevAlertTime = CurTime();
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments