Indicator · Pine Script v6 · On the chart

Nick Rypock Trailing Reverse

by everget

Nick Rypock Trailing Reverse plots a percentage trailing stop on the price chart and reverses its direction when the close crosses that level.

View on GitHub

GitHub stars948on the repository
Pine versionv6current
Lines of code64
Settings3inputs
LicenceGPL-3.0
Last update10 days ago18 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

64 lines of Pine Script v6 from trailing_stops/nrtr_nick_rypock_trailing_reverse.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

nrtr_nick_rypock_trailing_reverse.pine
//@version=6
// Copyright (c) 2021-present, Alex Orekhov (everget)
// Nick Rypock Trailing Reverse (NRTR) script may be freely distributed under the terms of the GPL-3.0 license.
indicator('Nick Rypock Trailing Reverse', shorttitle = 'NRTR', overlay = true)

const string calcGroup = 'Calculation'
percentage = input.float(2, minval = 0, maxval = 100, step = 0.1, title = 'Coefficient of Correction, %', group = calcGroup) / 100

const string visualGroup = 'Visuals'
showLabels = input.bool(true, title = 'Show Buy/Sell Labels', group = visualGroup)
highlightState = input.bool(true, title = 'Highlight State', group = visualGroup)

//---

var int trend = 0
var float hp = close
var float lp = close
nrtr = close

if trend >= 0
    if close > hp
        hp := close
        hp
    nrtr := hp * (1 - percentage)
    if close <= nrtr
        trend := -1
        lp := close
        nrtr := lp * (1 + percentage)
        nrtr
else
    if close < lp
        lp := close
        lp
    nrtr := lp * (1 + percentage)
    if close > nrtr
        trend := 1
        hp := close
        nrtr := hp * (1 - percentage)
        nrtr

const color textColor = color.white
const color longColor = color.green
const color shortColor = color.red
const color longFillColor = color.new(color.green, 85)
const color shortFillColor = color.new(color.red, 85)

longStopPlot = plot(trend == 1 ? nrtr : na, title = 'Long Stop', style = plot.style_linebr, linewidth = 2, color = longColor)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? nrtr : na, title = 'Long Stop Start', location = location.absolute, style = shape.circle, size = size.tiny, color = longColor)
plotshape(buySignal and showLabels ? nrtr : na, title = 'Buy Label', text = 'Buy', location = location.absolute, style = shape.labelup, size = size.tiny, color = longColor, textcolor = textColor)

shortStopPlot = plot(trend == 1 ? na : nrtr, title = 'Short Stop', style = plot.style_linebr, linewidth = 2, color = shortColor)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? nrtr : na, title = 'Short Stop Start', location = location.absolute, style = shape.circle, size = size.tiny, color = shortColor)
plotshape(sellSignal and showLabels ? nrtr : na, title = 'Sell Label', text = 'Sell', location = location.absolute, style = shape.labeldown, size = size.tiny, color = shortColor, textcolor = textColor)

midPricePlot = plot(ohlc4, title = '', display = display.none, editable = false)

fill(midPricePlot, longStopPlot, title = 'Long State Filling', color = (highlightState and trend == 1 ? longFillColor : na))
fill(midPricePlot, shortStopPlot, title = 'Short State Filling', color = (highlightState and trend == -1 ? shortFillColor : na))

alertcondition(trend != trend[1], title = 'NRTR Direction Change', message = 'NRTR has changed direction, {{exchange}}:{{ticker}}')
alertcondition(buySignal, title = 'NRTR Buy', message = 'NRTR Buy, {{exchange}}:{{ticker}}')
alertcondition(sellSignal, title = 'NRTR Sell', message = 'NRTR Sell, {{exchange}}:{{ticker}}')

Overview

In an uptrend it trails below the highest close by the correction coefficient; in a downtrend it trails above the lowest close. A direction change marks a buy or sell, with optional labels and circles at the new stop. The coefficient sets the trail distance, and optional fills highlight the long or short state. Alerts fire on direction changes and on buy or sell signals. It is an indicator with no position sizing or exit rules.

Details

Published by

everget on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinepinescripttechnical-indicatorsindicatorsoscillatorbandsaveragetradingviewindicatormoving-average

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Coefficient of Correction, %float2percentage
Show Buy/Sell LabelsbooltrueshowLabels
Highlight StatebooltruehighlightState
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This indicator detects equal highs and lows by comparing prices within user-defined left and right bars using a tolerance percentage. It plots horizontal lines on the price chart for equal highs in one color and lows in another. A screener allows input of mult

Indicator v5 Support & resistanceTrend
Updated 1 year ago · MPL-2.0 GitHub repository of ICT Equal Highs and Lows with Screener
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator calculates an ATR trailing stop line derived from the highest high minus an average true range multiple over a specified lookback period. It plots the trailing stop line directly on the price chart and colors price bars based on whether the clos

Indicator v5 TrendVolatility & bands
Updated 2 months ago · MIT GitHub repository of ATR Trailing Stoploss

All Candlestick Patterns

by shunjizhan
292 stars

All Candlestick Patterns detects and highlights a wide range of bullish, bearish, and neutral candlestick patterns directly on the price chart. It features optional trend filtering using either a 50-period simple moving average or a combination of 50-period an

Indicator v4 Candlestick patternsTrend
Updated 3 years ago · None stated GitHub repository of All Candlestick Patterns

NVDA Trend Ribbon

by longsurf-ai
277 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated yesterday · MIT GitHub repository of NVDA Trend Ribbon

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers