Strategy · Pine Script v6 · On the chart

Tn Sovereign Donchian Breakout

by raybird· code credited to TeleNexus Hunted & Sovereignly Rewritten

This strategy plots the Donchian Channel bands on the price chart to identify breakouts.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code87
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update2 months ago15 Aug 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

87 lines of Pine Script v6 from strategies/TnSovereignDonchianV6.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

TnSovereignDonchianV6.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TeleNexus Hunted & Sovereignly Rewritten
// Optimized for Forex (EURUSD, GBPUSD) 30m/1h timeframes.
//@version=6

strategy("Tn Sovereign Donchian Breakout v6", overlay=true, initial_capital=10000, default_qty_type=strategy.fixed, default_qty_value=1)

// ==========================================
// ⚙️ INPUTS & CONFIGURATION
// ==========================================

// --- Indicator Settings ---
int donchian_len = input.int(25, "Donchian Channel Length", minval=1, group="Indicator")

// --- Strategy Rules ---
int target_hour  = input.int(17, "Order Placement Hour (Exchange Time)", minval=0, maxval=23, group="Execution")
int valid_bars   = input.int(60, "Order Validity (Bars)", minval=1, group="Execution")

// --- Risk Management ---
float lot_size   = input.float(1000.0, "Position Volume", minval=0.1, group="Risk")

// ==========================================
// 📐 INDICATOR CALCULATIONS
// ==========================================

// Calculate Donchian Channel using the highest high and lowest low of closed bars [1]
// This defines the breakout levels.
float upper_band = ta.highest(high, donchian_len)[1]
float lower_band = ta.lowest(low, donchian_len)[1]

// Visualizing the channel
plot(upper_band, "Donchian Upper", color=color.new(color.green, 0), linewidth=2)
plot(lower_band, "Donchian Lower", color=color.new(color.red, 0), linewidth=1)

// ==========================================
// 🕒 TIME LOGIC
// ==========================================

// Check if current bar's hour matches the target hour
bool is_target_time = (hour == target_hour) and (minute == 0)

// Persistent state for order tracking
var float pending_stop_price = na
var int   entry_bar_index    = 0

// ==========================================
// 🚀 ORDER EXECUTION (BUY STOP)
// ==========================================

// 1. Placement phase at the specific hour
if is_target_time
    pending_stop_price := upper_band
    entry_bar_index    := bar_index
    
    // Place a STOP entry: order fills only if price breaches the level upward.
    strategy.entry("Sovereign Breakout", strategy.long, stop=pending_stop_price, comment="Breakout Limit", qty=lot_size)

// 2. Cancellation phase if not filled within validity window
int bars_passed = bar_index - entry_bar_index

if (strategy.opentrades == 0) and (bars_passed >= valid_bars)
    strategy.cancel("Sovereign Breakout")
    pending_stop_price := na

// ==========================================
// 🚪 EXIT STRATEGY
// ==========================================

// Standard Donchian exit: Sell if price hits the lower band.
if strategy.opentrades > 0
    strategy.exit("Exit Sovereign", "Sovereign Breakout", stop=lower_band, comment="Lower Band Hit")

// ==========================================
// 🎨 VISUALIZATION & HUD
// ==========================================

// Background highlight at order placement hour
bgcolor(is_target_time ? color.new(color.blue, 85) : na, title="Placement Window")

// Visual marker for target hour
plotshape(is_target_time ? high : na, 
     title="Execution Hour Marker", 
     location=location.abovebar, 
     color=color.green, 
     style=shape.triangleup, 
     text="HUNT", 
     size=size.small)

Overview

Tn Sovereign Donchian Breakout enters a long position by placing a buy stop order when price breaks above the upper band during a target execution hour. The order remains open until filled or canceled if unfilled after a set number of bars. It exits on a hit to the lower band or at the end of the validity window. The main settings adjust the channel length, target execution hour, order validity period, and position size. It draws all elements directly on the price chart with no separate pane.

Details

Published by

raybird on GitHub

Code credit

TeleNexus Hunted & Sovereignly Rewritten, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Volatility & bands, Support & resistance

Markets

Forex

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.

Settings

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

SettingTypeDefaultVariable
Donchian Channel Lengthint25donchian_len
Order Placement Hour (Exchange Time)int17target_hour
Order Validity (Bars)int60valid_bars
Position Volumefloat1000.0lot_size
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
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
11 stars

Calculates upper and lower Donchian Channel bands over a customizable lookback length and plots them on the main price chart. At a specified exchange hour, the strategy places a long buy stop order at the upper Donchian Channel level. Unfilled pending orders a

Strategy v6 BreakoutSupport & resistance
Updated 5 months ago · Apache-2.0 GitHub repository of Estrategia Donchian Breakout
6 stars

This overlay strategy builds independent timed session ranges and marks range, trendline, mean, VWAP, and high-low levels when those displays are enabled. It enters on range breakouts and exits with strategy exits, choosing among range, ATR, fixed-point, and r

Strategy v5 Sessions & timeBreakout
Updated 7 months ago · None stated GitHub repository of MSG Enhanced LEGO System Strategy
3 stars

Donchian Channel Breakout is a Pine Script v5 strategy drawn on the price chart. It enters long when close crosses above the previous upper Donchian band and short when close crosses below the previous lower band, reversing with the opposite signal. An ATR tra

Strategy v5 BreakoutVolatility & bands
Updated 7 months ago · MIT GitHub repository of Donchian Channel Breakout

The Range Percent Breakout Strategy identifies range contraction and inside bar patterns where the current bar's range is within a specified percentage threshold of the previous bar. When this condition is met while flat, breakout levels are established above

Strategy v5 BreakoutVolatility & bands
Updated 5 months ago · None stated GitHub repository of Range Percent 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