Nick Rypock Trailing Reverse,NRTR[everget] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
l3UBcnK.png

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:
Thanks so much for this, what do we need to add for buy and sell signal alerts?
alerts added

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

input CoeffOfCorrection = 1.5; # "Coefficient of Correction, %"
input showLabels = yes;        # "Show Buy/Sell Labels ?"
input ShowCloud  = yes;        # "Apply Ribbon ?"
input ShowLines  = yes;
input alerts   = yes;
input sound    = {default "NoSound", "Ding", "Bell", "Chimes", "Ring"};

def na = Double.NaN;
def c = close;
def ohlc = ohlc4;
def h = high;
def l = low;
def trend;
def hp;
def lp;
def nrtr;

def percentage = CoeffOfCorrection * 0.01;

if trend[1] >= 0 {
    if c > hp[1] {
        hp = c;
        nrtr = hp * (1 - percentage);
        lp = lp[1];
        trend = trend[1];
    } else {
        if c <= nrtr[1] {
            hp = hp[1];
            trend = -1;
            lp = c;
            nrtr = lp * (1 + percentage);
        } else {
            hp = hp[1];
            nrtr = nrtr[1];
            lp = lp[1];
            trend = trend[1];
        }
    }
} else {
    if c < lp[1] {
        lp = c;
        nrtr = lp * (1 + percentage);
        hp = hp[1];
        trend = trend[1];
    } else {
        if c > nrtr[1] {
            trend = 1;
            hp = c;
            nrtr = hp * (1 - percentage);
            lp = lp[1];
        } else {
            hp = hp[1];
            nrtr = nrtr[1];
            lp = lp[1];
            trend = trend[1];
        }
    }
}
def buySignal = trend == 1 and trend[1] == -1;
plot longStopPlot = if IsNaN(c) then na else if trend == 1 then nrtr else na;
longStopPlot.SetDefaultColor(CreateColor(76, 165, 80));
longStopPlot.SetHiding(!ShowLines);

plot PointUp = if buySignal then nrtr else na;
PointUp.SetDefaultColor(CreateColor(76, 165, 80));
PointUp.SetStyle(Curve.POINTS);
PointUp.SetLineWeight(3);
PointUp.SetHiding(!ShowLines);

def sellSignal = trend == -1 and trend[1] == 1;
plot shortStopPlot = if IsNaN(c) then na else if trend == 1 then na else nrtr;
shortStopPlot.SetDefaultColor(CreateColor(255, 82, 82));
shortStopPlot.SetHiding(!ShowLines);

plot PointDn = if sellSignal then nrtr else na;
PointDn.SetDefaultColor(CreateColor(255, 82, 82));
PointDn.SetStyle(Curve.POINTS);
PointDn.SetLineWeight(3);
PointDn.SetHiding(!ShowLines);

#--- Bubbles
AddChartBubble(buySignal and showLabels, If(ShowLines, nrtr, l), "Buy", CreateColor(76, 165, 80), no);
AddChartBubble(sellSignal and showLabels, If(ShowLines, nrtr, h), "Sell", CreateColor(255, 82, 82), yes);
#---Clouds
AddCloud(if ShowCloud then ohlc else na, longStopPlot, CreateColor(0, 22, 0), CreateColor(0, 22, 0));
AddCloud(if ShowCloud then shortStopPlot else na, ohlc, CreateColor(44, 0, 0), CreateColor(44, 0, 0));

#---- Alerts
Alert(alerts and buySignal, "Buy Signal", Alert.BAR, sound);
Alert(alerts and sellSignal, "Sell Signal", Alert.BAR, sound);

#--- END Code
 
Hi,
Great indicator,
I would like to add label with the trailing stop value;
Thank you in advance
add this at the end of the code.

CSS:
input showLabel = yes;
AddLabel(showLabel, "Trailing Value ($" + ROUND(nrtr, 2) + ")", if trend>0 then Color.LIGHT_GREEN else Color.LIGHT_RED);
 
View attachment 16194
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
cAN YOU MAKE THIS A STRATEGY?

,
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
231 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top