Strategy · Pine Script v6 · On the chart

Seykota Alt 45: Dual Momentum

by trustdan· code credited to danieltuckerrust

This strategy enters long or short when price breaks a Donchian channel and RSI confirms the same direction.

View on GitHub

GitHub stars16on the repository
Pine versionv6current
Lines of code145
Settings36inputs
LicenceNone statedfile: MPL-2.0
Last update11 months ago3 Nov 2025

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

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

seykota_alt45_dual_momentum_confirmation.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © danieltuckerrust
// ALTERNATIVE 45: Dual-Momentum Confirmation
// THEORY: Require BOTH price momentum (Donchian) AND oscillator momentum (RSI) to enter
// - ENTRY: Donchian breakout AND RSI confirms (>50 for longs, <50 for shorts)
// - EXIT: Alt39's proven age-based profit targets (young 4N-7N-10N, mature 3N-6N-9N, aging 2N-4N-6N)
// INSIGHT: Many Donchian breakouts fail when RSI is weak. Wait for oscillator confirmation.
// HYPOTHESIS: Filtering false breakouts reduces whipsaws, especially on commodities (FCX problem)
// Expected to improve: Commodities (avoid false breakouts), Energy (reduce chop), Financials (better entries)

//@version=6
strategy("Seykota Alt 45: Dual Momentum v1.0",
     overlay=true,
     initial_capital=100000,
     commission_type=strategy.commission.percent, commission_value=0.005,
     slippage=2,
     default_qty_type=strategy.fixed, default_qty_value=0,
     pyramiding=10,
     max_bars_back=5000)

allowLong = input.bool(true, "Allow LONGs?"), allowShort = input.bool(true, "Allow SHORTs?")
entryLen = input.int(55, "Donchian ENTRY", minval=10), nLen = input.int(20, "N = ATR length", minval=5)
stopN = input.float(2.0, "Initial stop (N)", minval=0.5, step=0.25)
trailLen = input.int(22, "Trail lookback", minval=5), trailN = input.float(3.0, "Trail (N)", minval=0.5, step=0.25)
addStepN = input.float(0.5, "Add every X*N", minval=0.25, step=0.25), maxUnits = input.int(4, "Max units", minval=1, maxval=10)
riskPct = input.float(1.0, "Risk % per unit", minval=0.1, maxval=5, step=0.1)

// RSI Momentum Filter
useRsiFilter = input.bool(true, "Use RSI confirmation?")
rsiLen = input.int(14, "RSI length", minval=5)
rsiLongThresh = input.float(50.0, "RSI long threshold", minval=30, maxval=70)
rsiShortThresh = input.float(50.0, "RSI short threshold", minval=30, maxval=70)

// Age-Based Targets (from Alt39)
useTargets = input.bool(true, "Use age-based targets?")
youngAge = input.int(15, "Young pos threshold (bars)", minval=5), matureAge = input.int(30, "Mature pos threshold (bars)", minval=10)
youngT1 = input.float(4.0, "Young T1 (N)", minval=1, step=0.5), youngT2 = input.float(7.0, "Young T2 (N)", minval=1, step=0.5), youngT3 = input.float(10.0, "Young T3 (N)", minval=1, step=0.5)
standardT1 = input.float(3.0, "Standard T1 (N)", minval=1, step=0.5), standardT2 = input.float(6.0, "Standard T2 (N)", minval=1, step=0.5), standardT3 = input.float(9.0, "Standard T3 (N)", minval=1, step=0.5)
agingT1 = input.float(2.0, "Aging T1 (N)", minval=1, step=0.5), agingT2 = input.float(4.0, "Aging T2 (N)", minval=1, step=0.5), agingT3 = input.float(6.0, "Aging T3 (N)", minval=1, step=0.5)

useMarket = input.bool(false, "Use regime filter?"), marketSym = input.symbol("SPY", "Market symbol")
marketTF = input.timeframe("D", "Regime TF"), marketLen = input.int(200, "Market MA", minval=50)
minVol = input.int(0, "Min volume", minval=0), showSignals = input.bool(true, "Plot signals?"), plotDon = input.bool(true, "Plot Donchian?")
fromDate = input.time(defval=timestamp("2022-01-01T00:00:00"), title="FROM", confirm=true)
toDate = input.time(defval=timestamp("2099-12-31T23:59:59"), title="TO", confirm=true)
flatAtFrom = input.bool(true, "FLAT at range start?")
isRangeStart = (time[1] < fromDate) and (time >= fromDate)
if flatAtFrom and isRangeStart and strategy.position_size != 0
    strategy.close_all(comment="Flat at FROM")

sharesForUnit(_e, _n) =>
    r = _e * (riskPct/100.0)
    psr = math.max(stopN * _n, syminfo.mintick)
    math.max(1, math.floor(r / psr))

inRange = (time >= fromDate) and (time <= toDate)
N = ta.atr(nLen), volMA = ta.sma(volume, 20), liqOK = volMA >= minVol
donHi = ta.highest(high, entryLen), donLo = ta.lowest(low, entryLen)
donHiPrev = donHi[1], donLoPrev = donLo[1]
trailHighest = ta.highest(high, trailLen), trailLowest = ta.lowest(low, trailLen)

// RSI Momentum Confirmation
rsi = ta.rsi(close, rsiLen)
rsiLongOK = not useRsiFilter or (rsi > rsiLongThresh)  // RSI must be bullish for longs
rsiShortOK = not useRsiFilter or (rsi < rsiShortThresh)  // RSI must be bearish for shorts

mClose = request.security(marketSym, marketTF, close), mMA = request.security(marketSym, marketTF, ta.sma(close, marketLen))
longRegOK = not useMarket or (mClose > mMA), shortRegOK = not useMarket or (mClose < mMA)

// DUAL MOMENTUM: Both price breakout AND RSI confirmation required
longBreak = allowLong and liqOK and longRegOK and rsiLongOK and (close > donHiPrev)
shortBreak = allowShort and liqOK and shortRegOK and rsiShortOK and (close < donLoPrev)

var float N_entry = na, var float entryPrice = na, var float lastAddLong = na, var float lastAddShort = na
var int units = 0, var int barsInPos = 0, var bool t1 = false, var bool t2 = false, var bool t3 = false
inPos = strategy.position_size != 0, inLong = strategy.position_size > 0, inShort = strategy.position_size < 0
if inPos
    barsInPos += 1
else
    barsInPos := 0, units := 0, lastAddLong := na, lastAddShort := na, N_entry := na, entryPrice := na, t1 := false, t2 := false, t3 := false

if inRange and not inPos and longBreak
    N_entry := N, entryPrice := close, strategy.entry("L", strategy.long, qty=sharesForUnit(strategy.equity, N_entry))
    units := 1, lastAddLong := close
if inRange and not inPos and shortBreak
    N_entry := N, entryPrice := close, strategy.entry("S", strategy.short, qty=sharesForUnit(strategy.equity, N_entry))
    units := 1, lastAddShort := close

if inRange and inLong and units < maxUnits and high >= nz(lastAddLong) + addStepN * N_entry
    strategy.entry("L", strategy.long, qty=sharesForUnit(strategy.equity, N_entry)), units += 1, lastAddLong := close
if inRange and inShort and units < maxUnits and low <= nz(lastAddShort) - addStepN * N_entry
    strategy.entry("S", strategy.short, qty=sharesForUnit(strategy.equity, N_entry)), units += 1, lastAddShort := close

// AGE-BASED TARGETS (from Alt39 - proven winner)
var float activeT1 = na, var float activeT2 = na, var float activeT3 = na
if useTargets and inLong and not na(entryPrice) and not na(N_entry)
    if barsInPos <= youngAge
        activeT1 := youngT1, activeT2 := youngT2, activeT3 := youngT3
    else if barsInPos <= matureAge
        activeT1 := standardT1, activeT2 := standardT2, activeT3 := standardT3
    else
        activeT1 := agingT1, activeT2 := agingT2, activeT3 := agingT3

    if not t1 and high >= entryPrice + activeT1 * N_entry
        strategy.close("L", qty=sharesForUnit(strategy.equity, N_entry), comment="T1"), t1 := true
    if t1 and not t2 and high >= entryPrice + activeT2 * N_entry
        strategy.close("L", qty=sharesForUnit(strategy.equity, N_entry), comment="T2"), t2 := true
    if t2 and not t3 and high >= entryPrice + activeT3 * N_entry
        strategy.close("L", qty=sharesForUnit(strategy.equity, N_entry), comment="T3"), t3 := true

if useTargets and inShort and not na(entryPrice) and not na(N_entry)
    if barsInPos <= youngAge
        activeT1 := youngT1, activeT2 := youngT2, activeT3 := youngT3
    else if barsInPos <= matureAge
        activeT1 := standardT1, activeT2 := standardT2, activeT3 := standardT3
    else
        activeT1 := agingT1, activeT2 := agingT2, activeT3 := agingT3

    if not t1 and low <= entryPrice - activeT1 * N_entry
        strategy.close("S", qty=sharesForUnit(strategy.equity, N_entry), comment="T1"), t1 := true
    if t1 and not t2 and low <= entryPrice - activeT2 * N_entry
        strategy.close("S", qty=sharesForUnit(strategy.equity, N_entry), comment="T2"), t2 := true
    if t2 and not t3 and low <= entryPrice - activeT3 * N_entry
        strategy.close("S", qty=sharesForUnit(strategy.equity, N_entry), comment="T3"), t3 := true

var float stopL = na, var float stopS = na
if inRange and inLong
    stopL := math.round_to_mintick(math.max(entryPrice - stopN * N_entry, trailHighest - trailN * N_entry))
    strategy.exit("L-EXIT", from_entry="L", stop=stopL)
else
    stopL := na
if inRange and inShort
    stopS := math.round_to_mintick(math.min(entryPrice + stopN * N_entry, trailLowest + trailN * N_entry))
    strategy.exit("S-EXIT", from_entry="S", stop=stopS)
else
    stopS := na

plot(plotDon ? donHi : na, "DonHi", color=color.new(color.blue, 40))
plot(plotDon ? donLo : na, "DonLo", color=color.new(color.blue, 40))
plotshape(showSignals and longBreak, title="L", style=shape.triangleup, location=location.belowbar, size=size.tiny, color=color.new(color.green, 0))
plotshape(showSignals and shortBreak, title="S", style=shape.triangledown, location=location.abovebar, size=size.tiny, color=color.new(color.red, 0))
// Color based on position age: green = young, orange = mature, red = aging
ageColor = barsInPos <= youngAge ? color.green : (barsInPos <= matureAge ? color.orange : color.red)
plot(showSignals and inLong ? stopL : na, "Stop", color=color.new(ageColor, 0), style=plot.style_linebr, linewidth=2)
plot(showSignals and inShort ? stopS : na, "Stop", color=color.new(ageColor, 0), style=plot.style_linebr, linewidth=2)

Overview

Seykota Alt 45: Dual Momentum sizes each unit from a risk percent of equity and can add units after a set ATR advance, up to a unit limit. An initial ATR stop and a trailing stop manage risk, while optional age-based targets scale out at three ATR multiples that tighten as the position ages. An optional market moving average can filter the regime. It plots on the price chart.

Details

Published by

trustdan on GitHub

Code credit

danieltuckerrust, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Oscillators & momentum, Volatility & bands, Breakout

Markets

Stocks, Oil & commodities

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction

Settings

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

SettingTypeDefaultVariable
Allow LONGs?booltrueallowLong
Allow SHORTs?booltrueallowShort
Donchian ENTRYint55entryLen
N = ATR lengthint20nLen
Initial stop (N)float2.0stopN
Trail lookbackint22trailLen
Trail (N)float3.0trailN
Add every X*Nfloat0.5addStepN
Max unitsint4maxUnits
Risk % per unitfloat1.0riskPct
Use RSI confirmation?booltrueuseRsiFilter
RSI lengthint14rsiLen
Show all 36 settings
SettingTypeDefaultVariable
RSI long thresholdfloat50.0rsiLongThresh
RSI short thresholdfloat50.0rsiShortThresh
Use age-based targets?booltrueuseTargets
Young pos threshold (bars)int15youngAge
Mature pos threshold (bars)int30matureAge
Young T1 (N)float4.0youngT1
Young T2 (N)float7.0youngT2
Young T3 (N)float10.0youngT3
Standard T1 (N)float3.0standardT1
Standard T2 (N)float6.0standardT2
Standard T3 (N)float9.0standardT3
Aging T1 (N)float2.0agingT1
Aging T2 (N)float4.0agingT2
Aging T3 (N)float6.0agingT3
Use regime filter?boolfalseuseMarket
Market symbolsymbolSPYmarketSym
Regime TFtimeframeDmarketTF
Market MAint200marketLen
Min volumeint0minVol
Plot signals?booltrueshowSignals
Plot Donchian?booltrueplotDon
FROMtimetimestamp("2022-01-01T00:00:00")fromDate
TOtimetimestamp("2099-12-31T23:59:59")toDate
FLAT at range start?booltrueflatAtFrom
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 trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

均线突破交易系统

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 均线突破交易系统

Momentum Rider DAILY FINAL

by greenpeas007
58 stars

This strategy combines exponential moving averages (EMA 9, 21, 50), RSI, MACD, and Supertrend indicators to enter long positions. It triggers trades using six dynamic setups based on momentum breakouts, EMA crossovers, and pullbacks. Position sizing is compute

Strategy v6 TrendOscillators & momentum Repaints
Updated 4 months ago · Custom licence GitHub repository of Momentum Rider DAILY FINAL
57 stars

This strategy identifies trend reversals through market structure changes (CHoCH) filtered by MACD momentum. It initiates long positions on bullish structure breaks when MACD is positive and above its signal line, and short positions on bearish breaks when MAC

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of Market Structure MACD 4H + Trailing

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