Strategy library

Volatility System strategy in Pine Script

Goes long or short when the close moves more than a multiple of the ATR in a single bar.

ATR · long and short · by EduardoMattje · Mozilla Public License 2.0

What is its backtest worth?

A parameter sweep finds the best setting of the Volatility System strategy. PineTester tells you if it holds up: whether the best result was only picked after the fact, what it makes with fees, what you could have known at the time (a walk-forward on data the pick did not see) and how deep it fell along the way. On the free start, your first own backtest gets the full evaluation; its trade list and result file come with the full report or a plan.

Creates a draft on Binance BTC/USDT 4h over about six and a half years with 0.1% commission per order and 2 ticks slippage; you start it yourself. A backtest uses credits; new accounts receive free credits.

The rules

  • Enters long when the change from the previous close is larger than the ATR (times the multiplier) of the bar before; short when the drop is larger.
  • Has no separate exit: each opposite signal turns the position around.
  • Invests the whole account in each trade (100% of equity, set in the code).

What to watch for

  • Large single-bar moves are rare on 4h bars; check how many trades the backtest has.
  • A full-size position that only turns on the next large move can hold through long declines – check the largest drop.

How PineTester judges a backtest, with its sources: how we judge results.

The Pine Script code

The author's code with its licence notice (Mozilla Public License 2.0), with one change marked in the code: the same test conditions for every library strategy in its strategy() line – the whole account per trade (split over the entries where it adds to a position), 0.1% commission per order and 2 ticks slippage; the trading rules are unchanged. Pine Script v5; PineTester converts it to v6 automatically, so results can differ slightly from TradingView.

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EduardoMattje
// Modified by PineTester (2026-11-14): the same test conditions for every library strategy in strategy(): 100% of equity per entry,
// 0.1% commission per order, 2 ticks slippage, initial capital 10,000. The trading rules are unchanged.
//@version=5
strategy("Volatility System", overlay=false, margin_long=0, margin_short=0, process_orders_on_close=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, slippage=2)
// Inputs
var averageLength = input.int(14, "Average length", 2)
var multiplier = input.float(2.0, "Multiplier", 0.0, step=0.1)
// Calculations
atr = ta.atr(averageLength) * multiplier
closingChange = ta.change(close, 1)
atrPenetration(int signal) =>
    res = closingChange * signal > atr[1]
longCondition = atrPenetration(1)
shortCondition = atrPenetration(-1)
// Order calls
if (longCondition)
    strategy.entry(strategy.direction.long, strategy.long)
if (shortCondition)
    strategy.entry(strategy.direction.short, strategy.short)
// Visuals
plot(atr, "ATR", color.white, 2)
plot(math.abs(closingChange), "Absolute close change", color.red)
  • PresentTrend – An ATR band follows the price and switches sides with the Money Flow Index; a turn of the band opens the trade.
  • Chandelier Exit + ZLSMA – A Chandelier Exit turn opens a trade only when the price also crosses a zero-lag least squares average (ZLSMA).
  • Donchian Channel MACD Trend – A breakout of the Donchian channel, confirmed by the MACD, with a stop a multiple of the ATR away.
  • Volatility Capture RSI-Bollinger – A trailing line built from wide Bollinger Bands, with an RSI filter on the entries.
  • RSI Mean Reversion – Buys a dip of the RSI in an uptrend and sells a spike in a downtrend, with a fixed take profit and stop.

Open-source script by EduardoMattje, shown under the Mozilla Public License 2.0. Not a recommendation; neither the author nor TradingView endorses PineTester. Backtests are hypothetical results on past data, not a forecast.