NRTR_Pilot__alert
Download scriptThe NRTR script is a technical analysis tool designed to identify market trends and dynamically calculate potential Stop-Loss (S/L) levels. Rather than using standard moving averages, it focuses on capturing the momentum of price action to provide visual cues for traders looking to manage risk based on current market volatility.
Core Logic Overview
The indicator operates by analyzing a specific lookback period (defaulting to 40 bars) to determine the "Average Range" of the market. This range is converted into a dynamic percentage value, which acts as a buffer. This buffer ensures that the calculated price levels are adjusted relative to how much the market is currently moving, making the tool more responsive to high-volatility periods and more stable during low-volatility periods.
Operational Modes
The script offers two distinct methods for determining the trend and the resulting price levels:
1. Standard Trend Detection (Open/Close Logic) When using the standard setting, the script evaluates the relationship between the opening and closing prices of candles.
- Trend Identification: If a candle closes higher than it opened, the script views the market as being in an upward trend. Conversely, a lower close indicates a downward trend.
- Price Tracking: The logic tracks the highest price reached during an uptrend or the lowest price reached during a downtrend to establish a baseline.
- Level Calculation: It then projects a "Stop-Loss" level by subtracting or adding the calculated volatility buffer from that baseline. When the price breaks these projected levels, the script flips its trend direction and recalculates the new level.
2. High/Low Balance Logic (Alternative Mode) In this mode, the script ignores the individual open and close prices of candles and instead looks at the midpoint of the candle's range (the average between the highest and lowest points reached).
- Balanced Trend: It compares the midpoint of the current candle to the midpoint of the previous one.
- Smoothing Effect: This method is generally smoother as it accounts for the full "reach" of the price action within a single bar, rather than just where the bar finished. The logic follows the same principle of projecting a volatility-adjusted buffer from these midpoints to determine support and resistance levels.
Visual Feedback and Alerts
- On-Chart Mapping: The script plots different colors (Blue, Red, Magenta, and Yellow) on the chart to represent the different Stop-Loss levels calculated by the logic. These serve as visual boundaries for traders.
- Real-Time Notifications: The tool includes an automated alert system. Whenever the trend logic detects a significant shift in price that triggers a new calculation (a "New S/L"), the script can send a pop-up notification to the user. This ensures that traders are immediately informed of structural changes in the market without having to watch the chart constantly.
//+------------------------------------------------------------------+
//| 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 bool alertOn = true;
extern int MaxBarsToCount = 200;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- drawing settings
SetIndexStyle(0,DRAW_ARROW);
SetIndexDrawBegin(0,AveragePeriod);
SetIndexStyle(1,DRAW_ARROW);
SetIndexDrawBegin(1,AveragePeriod);
SetIndexStyle(2,DRAW_ARROW);
SetIndexDrawBegin(2,AveragePeriod);
SetIndexStyle(3,DRAW_ARROW);
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]))
{
if(alertOn)Alert("New S/L at ",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]))
{
if(alertOn)Alert("New S/L at ",value);
PrevAlertTime = CurTime();
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments