Strategy · Pine Script v6 · On the chart

Forven S01509 - Simple Donchian 20/10 Breakout

by judder659

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks.

View on GitHub

GitHub stars361on the repository
Pine versionv6current
Lines of code101
Settings5inputs
LicenceAGPL-3.0
Last updatetoday28 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

101 lines of Pine Script v6 from forven/docs/pine/simple_donchian_breakout_demo.pine, published under AGPL-3.0. Keep the author's credit and licence lines when you reuse it.

simple_donchian_breakout_demo.pine
// ============================================================================
// Simple Donchian 20/10 Breakout — TradingView clone of Forven S01509
// ============================================================================
// Purpose: cross-validate Forven backtest math against TradingView using a
// strategy with bit-for-bit deterministic indicators (no EMA-style warmup).
//
// Forven side
//   strategy_id : S01509  (simple_donchian_breakout_demo)
//   dataset     : BTC/USDT-1h  (binance)
//   window      : 2025-04-19 16:00 UTC  →  2026-04-19 16:00 UTC  (8760 bars)
//   leverage    : 1x
//   fee model   : ~11 bps round-trip (5.5 bps per side) inferred from trades
//   entry       : close > highest(high, 20) of the PRIOR 20 bars
//   exit        : close < lowest(low, 10)   of the PRIOR 10 bars
//
// How to use
//   1. Open BINANCE:BTCUSDT on the 1H chart in TradingView.
//   2. Paste this script into the Pine Editor and Add to Chart.
//   3. Open the Strategy Tester panel. The script auto-restricts trades to
//      the Forven window, so TradingView's totals should line up with
//      Forven's combined (IS + OOS) figures below.
//
// Expected Forven numbers (leverage=1x, long-only, single-side)
//                        trades   win_rate   return_pct   profit_factor   max_dd
//   In-sample (8.4m)      103      0.2621       -0.345        0.539        0.369
//   Out-of-sample (3.6m)   35      0.4000       -0.026        0.947        0.147
//   Combined (~12m)       138      0.2971       -0.362        0.650        0.369 ~
//
// ~ = approximation. Max DD is max(IS, OOS) rather than recomputed from the
// joined return stream — true full-window drawdown may be slightly larger.
//
// Math note
//   pandas  df['high'].rolling(20).max().shift(1)
//   Pine    ta.highest(high[1], 20)   ==   ta.highest(high, 20)[1]
//   are bit-for-bit identical — no seeding / warmup ambiguity. Any residual
//   delta vs Forven should come from fee model precision and the open-bar
//   equity curve, not from indicator math.
// ============================================================================

//@version=6
strategy(
     title              = "Forven S01509 — Simple Donchian 20/10 Breakout",
     shorttitle         = "S01509",
     overlay            = true,
     pyramiding         = 0,
     initial_capital    = 10000,
     default_qty_type   = strategy.percent_of_equity,
     default_qty_value  = 100,
     commission_type    = strategy.commission.percent,
     commission_value   = 0.055,
     slippage           = 0,
     calc_on_every_tick = false,
     process_orders_on_close = true)

// ---- Inputs ----------------------------------------------------------------
entry_len = input.int(20, "Entry channel length (prior N-bar high)", minval = 2, group = "Signal")
exit_len  = input.int(10, "Exit channel length (prior N-bar low)",   minval = 2, group = "Signal")

use_window = input.bool(true,  "Restrict to Forven window",  group = "Date range")
// Hardcoded epoch ms (const int — Pine v6 requires this for input.time defval):
//   1745078400000 = 2025-04-19 16:00:00 UTC
//   1776614400000 = 2026-04-19 16:00:00 UTC
start_ts   = input.time(1745078400000, "Window start (UTC)", group = "Date range")
end_ts     = input.time(1776614400000, "Window end (UTC)",   group = "Date range")

// ---- Indicators ------------------------------------------------------------
// `ta.highest(high[1], N)` == rolling(N).max().shift(1) — the max over the
// N bars strictly BEFORE the current bar. Classic turtle breakout.
prior_high = ta.highest(high[1], entry_len)
prior_low  = ta.lowest(low[1],   exit_len)

plot(prior_high, "Prior 20-bar high", color = color.new(color.green, 0))
plot(prior_low,  "Prior 10-bar low",  color = color.new(color.red,   0))

// ---- Window gate -----------------------------------------------------------
in_window = not use_window or (time >= start_ts and time <= end_ts)

// ---- Signals ---------------------------------------------------------------
break_up   = close > prior_high
break_down = close < prior_low

if in_window and break_up
    strategy.entry("Long", strategy.long)

if break_down
    strategy.close("Long")

// Force-flat at window end so totals are directly comparable to Forven.
if use_window and (time > end_ts)
    strategy.close_all()

// ---- Visuals ---------------------------------------------------------------
plotshape(break_up   and in_window, title = "Long entry",
     style = shape.triangleup,   location = location.belowbar,
     color = color.new(color.green, 0), size = size.tiny)

plotshape(break_down, title = "Long exit",
     style = shape.triangledown, location = location.abovebar,
     color = color.new(color.red, 0),   size = size.tiny)

bgcolor(in_window ? color.new(color.blue, 92) : na, title = "In-window shading")

Overview

Forven S01509 - Simple Donchian 20/10 Breakout triggers a long entry when the closing price breaks above the highest high of the prior entry length. Positions are closed when the price falls below the lowest low of the prior exit length. Users can adjust channel lengths and filter trades by a custom UTC date window. It plots directly on the main price chart and relies entirely on channel exits without a hard stop loss.

Details

Published by

judder659 on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Trend, Support & resistance

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Entry channel length (prior N-bar high)int20entry_len
Exit channel length (prior N-bar low)int10exit_len
Restrict to Forven windowbooltrueuse_window
Window start (UTC)time1745078400000start_ts
Window end (UTC)time1776614400000end_ts
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 running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar
106 stars

Calculates multi-period logarithmic regression trend channels and deviation bands across up to twenty selectable lookback lengths directly on the price chart. It evaluates channel slopes and Pearson's correlation coefficient to detect market trends and generat

Strategy v5 TrendSupport & resistance Repaints
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced Trend Detection Strategy

This trend breakout strategy plots Donchian Channels consisting of upper, lower, and middle bands directly on the main price chart. Long positions enter when price touches the upper channel and pulls back to or below the middle band, placing a stop loss at the

Strategy v6 TrendBreakout
Updated 2 months ago · MPL-2.0 GitHub repository of Donchian Strategy - Dynamic TP, Fixed SL, 1% Risk, Daily Target
43 stars

This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-

Strategy v5 TrendBreakout Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m - Strategy Candle Bar
16 stars

This strategy trades Donchian breakouts measured on weekly bars while orders execute on the chart timeframe. It allows long and short entries when price breaks the prior weekly channel and exits against the shorter weekly channel. Position size risks a set per

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 4: Weekly Donchian

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