Indicator · Pine Script v6 · On the chart

Chande Kroll Stop (CKSTOP)

by mihakralj

The Chande Kroll Stop calculates volatility-based adaptive trailing stops for long and short positions.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code52
Settings3inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 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

52 lines of Pine Script v6 from lib/reversals/ckstop/ckstop.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

ckstop.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Chande Kroll Stop (CKSTOP)", "CKSTOP", overlay=true)

//@function Chande Kroll Stop — adaptive trailing stop using ATR-smoothed volatility
//          envelopes around rolling extremes, then smoothed through a second window.
//          Stage 1: first_high_stop = HH(p) - m*ATR, first_low_stop = LL(p) + m*ATR
//          Stage 2: StopShort = highest(first_high_stop, x), StopLong = lowest(first_low_stop, x)
//@param atr_period ATR and first-stop extreme lookback (default 10)
//@param multiplier ATR scaling factor (default 1.0)
//@param stop_period Second smoothing window (default 9)
//@returns [stop_long, stop_short] — two overlay stop levels
//@reference Chande & Kroll, "The New Technical Trader" (1994)
//@optimized O(1) per bar using ta.rma, ta.highest, ta.lowest
ckstop(simple int atr_period = 10, simple float multiplier = 1.0, simple int stop_period = 9) =>
    if atr_period < 1
        runtime.error("ATR period must be >= 1")
    if multiplier <= 0
        runtime.error("Multiplier must be > 0")
    if stop_period < 1
        runtime.error("Stop period must be >= 1")

    // True Range
    float tr = na(close[1]) ? high - low : math.max(high - low, math.max(math.abs(high - close[1]), math.abs(low - close[1])))

    // ATR via Wilder's RMA
    float atr = ta.rma(tr, atr_period)

    // Stage 1: First stops (volatility envelope)
    float hh = ta.highest(high, atr_period)
    float ll = ta.lowest(low, atr_period)
    float first_high_stop = hh - multiplier * atr
    float first_low_stop  = ll + multiplier * atr

    // Stage 2: Smoothed stops over stop_period
    float stop_short = ta.highest(first_high_stop, stop_period)
    float stop_long  = ta.lowest(first_low_stop, stop_period)

    [stop_long, stop_short]

// ── Inputs ──
int   i_atr_period  = input.int(10, "ATR Period", minval=1)
float i_multiplier  = input.float(1.0, "Multiplier", minval=0.01, step=0.1)
int   i_stop_period = input.int(9, "Stop Period", minval=1)

// ── Calculation ──
[stop_long, stop_short] = ckstop(i_atr_period, i_multiplier, i_stop_period)

// ── Plot ──
plot(stop_long,  "Stop Long",  color=color.green, linewidth=2)
plot(stop_short, "Stop Short", color=color.red,   linewidth=2)

Overview

Chande Kroll Stop (CKSTOP) determines an initial volatility envelope by subtracting or adding a scaled Average True Range from the highest high or lowest low over a set lookback period. It then applies a second lookback period to calculate the final long and short stop levels. Built for overlaying directly on the price chart, configurable inputs include ATR period, ATR multiplier, and stop period.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Volatility & bands, Support & resistance

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

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

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

SettingTypeDefaultVariable
ATR Periodint10i_atr_period
Multiplierfloat1.0i_multiplier
Stop Periodint9i_stop_period
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

[RS]Donchian Fans

by ricardosantos79
261 stars

This indicator plots Donchian Channel boundary lines along with dynamic fan projections directly on the price chart. It calculates the highest high, lowest low, and median price over a customizable lookback period. Whenever price establishes a new channel high

Indicator v4 Support & resistanceTrend
Updated 4 years ago · None stated GitHub repository of [RS]Donchian Fans

Dynamic Linear Regression

by TradersPost
218 stars

Dynamic Linear Regression calculates and plots linear regression trendlines and standard deviation channels directly on the price chart over a user-selected time period. Traders can configure static channels locked at the end time, dynamic channels that contin

Indicator v6 TrendSupport & resistance
Updated 3 months ago · None stated GitHub repository of Dynamic Linear Regression

Moon Dev Lunar Sniper

by moondevonyt
92 stars

Moon Dev Lunar Sniper is a multi-indicator overlay that scores confluence across fast and slow EMAs, RSI, MACD, DMI, and BB width to fire signals only when score meets the minimum threshold. It plots buy and sell signals on the price chart, highlights cosmic b

Indicator v6 TrendOscillators & momentum Repaints
Updated 8 weeks ago · Custom licence GitHub repository of Moon Dev Lunar Sniper

SuperTrend & Pivots

by dcaoyuan
55 stars

This overlay indicator plots a SuperTrend line on the price chart using a fixed ATR length of 10 and a factor of 3. When the trend direction is up it draws a green line and a light green fill toward the candle midpoint; when down it draws a red line and a ligh

Indicator v6 TrendVolatility & bands
Updated 6 months ago · Apache-2.0 GitHub repository of SuperTrend & Pivots
47 stars

The Ultimate Channel calculates an ultra-smoothed centerline alongside upper and lower volatility bands directly on the main price chart. It processes true range values through an advanced infinite impulse response smoothing filter to establish dynamic channel

Indicator v6 Volatility & bandsTrend
Updated 8 months ago · MIT GitHub repository of Ultimate Channel (UCHANNEL)

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