Strategy · Pine Script v6 · On the chart

Volatility Breakout (Larry Williams) [JR]

by jayadevrana

The Volatility Breakout (Larry Williams) strategy generates signals based on price movements relative to yesterday's range.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code77
Settings12inputs
LicenceMPL-2.0
Last update2 days ago26 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

77 lines of Pine Script v6 from scripts/larry-williams-volatility-breakout.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

larry-williams-volatility-breakout.pine.txt
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JayadevRana
//@version=6
// Larry Williams — Volatility Breakout, as he describes it in "Long-Term Secrets to Short-Term Trading":
// buy when price moves a fraction of yesterday's range away from the reference price, protect with a stop
// sized by the same range, and get out fast ("first profitable opening").
// TradingView cannot know tomorrow's open at tonight's close, so the reference is the CLOSE (a variant
// Williams also uses); the exit is taken at the open after the first profitable close.
strategy("Volatility Breakout (Larry Williams) [JR]", shorttitle = "LW Breakout", overlay = true,
     initial_capital = 100000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100,
     commission_type = strategy.commission.percent, commission_value = 0.02, slippage = 2,
     margin_long = 0, margin_short = 0, process_orders_on_close = false, pyramiding = 0)

G1 = "1 · Breakout"
kLong   = input.float(1.0, "Long: buy stop at close + k × yesterday's range", minval = 0.05, step = 0.05, group = G1)
kShort  = input.float(0.6, "Short: sell stop at close − k × range", minval = 0.05, step = 0.05, group = G1)
dirMode = input.string("Long only", "Direction", options = ["Long only", "Both", "Short only"], group = G1,
     tooltip = "Williams traded stock indices mostly from the long side")
G2 = "2 · Exit"
stopK    = input.float(0.5, "Stop: entry − k × range (0 = no stop)", minval = 0, step = 0.05, group = G2)
exitMode = input.string("Hold N days", "Exit", options = ["First profitable close", "Next open", "Hold N days"], group = G2)
holdN    = input.int(3, "Max days in trade", minval = 1, maxval = 30, group = G2)
G3 = "3 · Filters"
trendOn  = input.bool(false, "Trend filter: close above close N days ago", group = G3)
trendN   = input.int(20, "Trend lookback (days)", minval = 2, group = G3)
rangeMin = input.float(0.0, "Skip if yesterday's range < % of price", minval = 0, step = 0.1, group = G3)
G4 = "4 · Test window"
fromT = input.time(timestamp("2000-01-01T00:00:00"), "Trade from", group = G4)
toT   = input.time(timestamp("2100-01-01T00:00:00"), "Trade until", group = G4)
showLv = input.bool(true, "Show trigger levels", group = G4)

inWin   = time >= fromT and time <= toT
rng     = high - low
canLong = dirMode != "Short only"
canShrt = dirMode != "Long only"
trendUp = not trendOn or close > close[trendN]
trendDn = not trendOn or close < close[trendN]
rangeOK = rng >= close * rangeMin / 100
longTrig  = close + kLong * rng
shortTrig = close - kShort * rng
flat = strategy.position_size == 0

var float rngAtEntry = na
var int   entryBar   = na
if strategy.position_size != 0 and strategy.position_size[1] == 0
    rngAtEntry := rng[1]
    entryBar   := bar_index

// orders placed at this close work during the next bar
strategy.cancel_all()
if flat and inWin and rangeOK
    if canLong and trendUp
        strategy.entry("LW L", strategy.long, stop = longTrig)
    if canShrt and trendDn
        strategy.entry("LW S", strategy.short, stop = shortTrig)

if strategy.position_size > 0
    ep = strategy.position_avg_price
    if stopK > 0
        strategy.exit("LW L stop", "LW L", stop = ep - stopK * rngAtEntry)
    held = bar_index - entryBar + 1
    if (exitMode == "First profitable close" and close > ep) or exitMode == "Next open" or held >= holdN
        strategy.close("LW L", comment = "exit")
if strategy.position_size < 0
    ep = strategy.position_avg_price
    if stopK > 0
        strategy.exit("LW S stop", "LW S", stop = ep + stopK * rngAtEntry)
    held = bar_index - entryBar + 1
    if (exitMode == "First profitable close" and close < ep) or exitMode == "Next open" or held >= holdN
        strategy.close("LW S", comment = "exit")
if not inWin and not flat
    strategy.close_all(comment = "window end")

plot(showLv and flat and canLong ? longTrig : na, "Buy stop (next bar)", color.new(color.teal, 0), 1, plot.style_circles, offset = 1)
plot(showLv and flat and canShrt ? shortTrig : na, "Sell stop (next bar)", color.new(color.red, 0), 1, plot.style_circles, offset = 1)
plot(strategy.position_size > 0 and stopK > 0 ? strategy.position_avg_price - stopK * rngAtEntry : na, "Long stop", color.new(color.red, 0), 2, plot.style_linebr)
plot(strategy.position_size < 0 and stopK > 0 ? strategy.position_avg_price + stopK * rngAtEntry : na, "Short stop", color.new(color.red, 0), 2, plot.style_linebr)

Overview

Long entries occur when price surpasses the close by a user-defined multiple of the range, while short entries use a lower multiple. A trend filter can be applied, and trades can be skipped if the range is too small. Stop loss is set using the range multiplier, and positions exit after a specified number of days or at the next open. Trigger levels are plotted on the chart if enabled. The strategy supports backtesting with commissions and slippage.

Details

Published by

jayadevrana on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Volatility & bands, 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

algorithmic-tradingbacktestingema-crossoverpine-scriptpine-script-v6pinescriptrsitechnical-analysistrading-automationtrading-indicators

Settings

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

SettingTypeDefaultVariable
Long: buy stop at close + k × yesterday's rangefloat1.0kLong
Short: sell stop at close − k × rangefloat0.6kShort
DirectionstringLong onlydirMode
Stop: entry − k × range (0 = no stop)float0.5stopK
ExitstringHold N daysexitMode
Max days in tradeint3holdN
Trend filter: close above close N days agoboolfalsetrendOn
Trend lookback (days)int20trendN
Skip if yesterday's range < % of pricefloat0.0rangeMin
Trade fromtimetimestamp("2000-01-01T00:00:00")fromT
Trade untiltimetimestamp("2100-01-01T00:00:00")toT
Show trigger levelsbooltrueshowLv
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

257 stars

This strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
106 stars

This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 9:22 5 MIN 15 MIN BANKNIFTY

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
16 stars

This trend-following strategy adapts classic Donchian breakout channels according to market volatility regimes. It calculates an ATR percentile rank across a rolling lookback period, shifting dynamically between tighter breakout channels with smaller stops dur

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 1: Adaptive Volatility

This strategy executes breakout trades using two Donchian Channels alongside an optional 200-period EMA trend filter. Entries trigger when the price sets a new highest high or lowest low over the primary Donchian Channel period. Exits are managed via a shorter

Strategy v5 BreakoutTrend
Updated 1 year ago · None stated GitHub repository of Ruckard Walcrypto DoubleDonchian B002

Breakout Strategy

by JoelPasapera
11 stars

This strategy implements a channel breakout system directly on the main price chart. It calculates highest highs and lowest lows over configurable entry and exit periods using historical candles. A long entry triggers when the close breaks above the entry chan

Strategy v6 BreakoutTrend
Updated 5 months ago · Apache-2.0 GitHub repository of Breakout Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers