Creator Message:
This indicator was invented in 2001 by Konstantin Kopyrkin. The name "Nick Rypock" is derived from his surname reading in the opposite direction:
Kopyrkin -> Kopyr Kin -> Kin Kopyr -> Nik Rypok
The idea of the indicator is similar to the Chandelier Exit , but doesn't involve ATR component and uses a percentage instead.
A dynamic price channel is used to calculate the NRTR. The calculations involve only those prices that are included in the current trend and exclude the extremes related to the previous trend. The indicator is always at the same distance (in percent) from the extremes reached by prices (below the maximum peak for the current uptrend, above the minimum bottom for the current downtrend). [I added option to show the signal only]
Code - Update - Code fix, MTF, Label
CSS:
#https://www.tradingview.com/script/XAscppNW-Nick-Rypock-Trailing-Reverse-NRTR/
#// Copyright (c) 2021-present, Alex Orekhov (everget)
#study("Nick Rypock Trailing Reverse", shorttitle="NRTR"
# Converted by Sam4Cok@Samer800 - 10/2022
# Update - Added alerts by Sam4Cok@Samer800
# Update - code fix, added MTF and label by Sam4Cok@Samer800 - 11/2023
input showLabel = yes;
input timeframe = {Default "Chart", "Custom"};
input customTimeframe = AggregationPeriod.HOUR;
input source = FundamentalType.CLOSE; # "Source"
input cofPercentage = 1.5; # "Coefficient of Correction, %"
input showSignals = yes; # "Show Buy/Sell Labels ?"
input ShowCloud = yes; # "Apply Ribbon ?"
input ShowLines = yes;
input enableAlerts = yes;
input alertType = Alert.BAR;
input alertSound = Sound.NoSound;
def na = Double.NaN;
def last = isNaN(close);
def mtf = timeframe == timeframe."Custom";
def h = high;
def l = low;
def cof = cofPercentage / 100;
def percentage = cof;
#- MTF
def tfC = Fundamental(FundamentalType = source);
def mtfC = Fundamental(FundamentalType = source, Period = customTimeframe);
def c = if mtf then mtfC else tfC;
#--Color
DefineGlobalColor("up", CreateColor(76, 165, 80));
DefineGlobalColor("dn", CreateColor(255, 82, 82));
DefineGlobalColor("dup", CreateColor(0, 33, 0));
DefineGlobalColor("ddn", CreateColor(44, 0, 0));
def state = {default init, long, short};
def nrtr;
def hp;
def lp;
switch (state[1]) {
case init:
state = state.long;
lp = c;
hp = c;
nrtr = c;
case short:
if (c > nrtr[1]) {
state = state.long;
lp = lp[1];
hp = c;
nrtr = hp * (1 - percentage);
} else {
state = state[1];
if (c < lp[1]) {
lp = c;
} else {
lp = lp[1];
}
hp = hp[1];
nrtr = lp * (1 + percentage);
}
case long:
if (c <= nrtr[1]) {
state = state.short;
lp = c;
hp = hp[1];
nrtr = lp * (1 + percentage);
} else {
state = state[1];
if (c > hp[1]) {
hp = c;
} else {
hp = hp[1];
}
lp = lp[1];
nrtr = hp * (1 - percentage);
}
}
def trend = if state == state.long then 1 else if state == state.short then -1 else 0;
def change = last or trend != trend[1];
plot nrtrLine = if ShowLines and !change then nrtr else na;
nrtrLine.AssignValueColor(if trend > 0 then GlobalColor("up") else
if trend < 0 then GlobalColor("dn") else Color.GRAY);
plot Points = if change[1] then nrtrLine else na;
Points.AssignValueColor(if trend > 0 then GlobalColor("up") else
if trend < 0 then GlobalColor("dn") else Color.GRAY);
Points.SetStyle(Curve.POINTS);
Points.SetLineWeight(3);
#--- Bubbles
def buySignal = !last and change[1] and trend == 1;
def sellSignal = !last and change[1] and trend ==-1;
AddChartBubble(buySignal and showSignals, If(ShowLines, nrtr, l), "UP", GlobalColor("up"), no);
AddChartBubble(sellSignal and showSignals, If(ShowLines, nrtr, h), "DN", GlobalColor("dn"));
#---Clouds
def ohlc = ohlc4;
AddCloud(if ShowCloud then ohlc else na, nrtrLine, GlobalColor("dup"), GlobalColor("ddn"));
#-- Label
AddLabel(showLabel, "Trailing Value ($" + Round(nrtr, 2) + ")", if trend > 0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
#---- Alerts
Alert(enableAlerts and buySignal, "Buy Signal", alertType, alertSound);
Alert(enableAlerts and sellSignal, "Sell Signal", alertType, alertSound);
#--- END Code
Last edited: