Strategy · Pine Script v6 · On the chart

Turtle Breakout (Dennis & Eckhardt) [JR]

by jayadevrana

This strategy implements the classic Turtle Trading breakout rules on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code79
Settings13inputs
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

79 lines of Pine Script v6 from scripts/turtle-trading-rules.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

turtle-trading-rules.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
// The Turtle Trading rules (Richard Dennis & William Eckhardt, 1983) as published by former Turtles:
// enter on a 20-day (System 1) or 55-day (System 2) breakout, size each unit so 1 N (20-day ATR) = 1% of
// equity, stop 2 N from the last unit, add a unit every ½ N up to 4, exit on a 10-day / 20-day opposite breakout.
// Defaults = the setting optimised on gold daily 2006-2018 and validated on 2019-2026 (55/20 days, 1.5 N stop, 4 units, long only);
// the textbook System 1 is 20/10 days, 2 N stop, long and short.
strategy("Turtle Breakout (Dennis & Eckhardt) [JR]", shorttitle = "Turtles", overlay = true,
     initial_capital = 100000, commission_type = strategy.commission.percent, commission_value = 0.02, slippage = 2,
     margin_long = 0, margin_short = 0, pyramiding = 4, process_orders_on_close = false)

G1 = "1 · Breakout"
entryLen = input.int(55, "Entry: breakout of the last N days", minval = 5, group = G1, tooltip = "System 1 = 20, System 2 = 55")
exitLen  = input.int(20, "Exit: opposite breakout of the last N days", minval = 2, group = G1, tooltip = "System 1 = 10, System 2 = 20")
skipWin  = input.bool(false, "System 1 filter: skip the next breakout after a winner", group = G1)
dirMode  = input.string("Long only", "Direction", options = ["Both", "Long only", "Short only"], group = G1)
G2 = "2 · N, stops and units"
nLen     = input.int(20, "N = ATR length", minval = 5, group = G2)
stopN    = input.float(1.5, "Stop: last unit ± N ×", minval = 0.5, step = 0.25, group = G2)
riskPct  = input.float(1.0, "Unit size: 1 N move = % of equity", minval = 0.1, step = 0.1, group = G2)
maxUnits = input.int(4, "Max units", minval = 1, maxval = 4, group = G2)
addN     = input.float(0.5, "Add a unit every N ×", minval = 0.25, step = 0.25, group = G2)
maxLev   = input.float(2.0, "Cap: one unit ≤ equity × (leverage)", minval = 0.1, step = 0.1, group = G2)
G3 = "3 · Test window"
fromT  = input.time(timestamp("2000-01-01T00:00:00"), "Trade from", group = G3)
toT    = input.time(timestamp("2100-01-01T00:00:00"), "Trade until", group = G3)
showLv = input.bool(true, "Show channels", group = G3)

inWin   = time >= fromT and time <= toT
N       = ta.atr(nLen)
hiEntry = ta.highest(high, entryLen)
loEntry = ta.lowest(low, entryLen)
hiExit  = ta.highest(high, exitLen)
loExit  = ta.lowest(low, exitLen)
ready   = bar_index > math.max(entryLen, nLen) + 1 and not na(N) and not na(hiEntry) and not na(loEntry)   // a stop at na would be a market order
canLong = dirMode != "Short only"
canShrt = dirMode != "Long only"

unitQty = math.min(strategy.equity * riskPct / 100 / (N * syminfo.pointvalue), strategy.equity * maxLev / 4 / (close * syminfo.pointvalue))

var float nEntry = na
var bool  lastWin = false
if strategy.position_size != 0 and strategy.position_size[1] == 0
    nEntry := na(N[1]) ? N : N[1]
if strategy.closedtrades > strategy.closedtrades[1]
    lastWin := strategy.closedtrades.profit(strategy.closedtrades - 1) > 0

strategy.cancel_all()
units = strategy.opentrades
if strategy.position_size == 0 and inWin and ready and not (skipWin and lastWin)
    if canLong
        strategy.entry("T L1", strategy.long, qty = unitQty, stop = hiEntry + syminfo.mintick)
    if canShrt
        strategy.entry("T S1", strategy.short, qty = unitQty, stop = loEntry - syminfo.mintick)
if strategy.position_size == 0 and skipWin and lastWin and (high > hiEntry[1] or low < loEntry[1])
    lastWin := false   // the skipped breakout happened; the next one is taken

var float stopPx = na
if strategy.position_size > 0
    lastP = strategy.opentrades.entry_price(units - 1)
    stopPx := math.max(lastP - stopN * nEntry, loExit)
    if units < maxUnits and inWin and not na(nEntry)
        strategy.entry("T L" + str.tostring(units + 1), strategy.long, qty = unitQty, stop = lastP + addN * nEntry)
    strategy.exit("T L out", stop = stopPx)
else if strategy.position_size < 0
    lastP = strategy.opentrades.entry_price(units - 1)
    stopPx := math.min(lastP + stopN * nEntry, hiExit)
    if units < maxUnits and inWin and not na(nEntry)
        strategy.entry("T S" + str.tostring(units + 1), strategy.short, qty = unitQty, stop = lastP - addN * nEntry)
    strategy.exit("T S out", stop = stopPx)
else
    stopPx := na
if not inWin and strategy.position_size != 0
    strategy.close_all(comment = "window end")

plot(showLv ? hiEntry : na, "Entry high (next bar)", color.new(color.teal, 30), 1, offset = 1)
plot(showLv ? loEntry : na, "Entry low (next bar)", color.new(color.red, 30), 1, offset = 1)
plot(strategy.position_size != 0 ? stopPx : na, "Stop / exit", color.new(color.orange, 0), 2, plot.style_linebr, offset = 1)

Overview

Turtle Breakout (Dennis & Eckhardt) [JR] enters positions when price breaks above or below highest high or lowest low channel levels. Position size is dynamically calculated using ATR volatility so that one ATR move equals a specified percentage of equity. The strategy pyramids up to four units as price advances and sets ATR-based stops alongside opposite Donchian channel breakout exits. Configurable inputs adjust entry and exit lengths, risk percentage, ATR period, maximum units, and direction mode.

Details

Published by

jayadevrana on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Trend, Volatility & bands

Markets

Any symbol

Timeframes

H4 and above

Risk Notes

  • The strategy can add several entries in the same direction

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
Entry: breakout of the last N daysint55entryLen
Exit: opposite breakout of the last N daysint20exitLen
System 1 filter: skip the next breakout after a winnerboolfalseskipWin
DirectionstringLong onlydirMode
N = ATR lengthint20nLen
Stop: last unit ± N ×float1.5stopN
Unit size: 1 N move = % of equityfloat1.0riskPct
Max unitsint4maxUnits
Add a unit every N ×float0.5addN
Cap: one unit ≤ equity × (leverage)float2.0maxLev
Trade fromtimetimestamp("2000-01-01T00:00:00")fromT
Trade untiltimetimestamp("2100-01-01T00:00:00")toT
Show all 13 settings
SettingTypeDefaultVariable
Show channelsbooltrueshowLv
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