//@version=6 // SPDX-License-Identifier: MIT // RegimeBreak: BTC signal leg only; Treasury carry is modeled separately in the website. No bond return in TradingView Strategy Tester. strategy("RegimeBreak | Volatility-scaled breakout", overlay=true, initial_capital=10000, currency=currency.USD, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.15, slippage=0, margin_long=100, margin_short=100, process_orders_on_close=false, calc_on_every_tick=false) entryN = input.int(20, "Entry channel (days)", minval=2) exitN = input.int(10, "Exit channel (days)", minval=2) regimeN = input.int(80, "Regime SMA (days)", minval=2) volN = input.int(20, "Realized volatility (days)", minval=2) target = input.float(35, "Annual volatility sizing target (%)", minval=1, maxval=100) / 100 cap = input.float(80, "Max entry allocation (%)", minval=1, maxval=90) / 100 start = input.time(timestamp("01 Jan 2022 00:00 +0000"), "Start (UTC)") finish = input.time(timestamp("25 Nov 2026 00:00 +0000"), "End exclusive (UTC; extend for forward test)") if not (timeframe.isdaily and timeframe.multiplier == 1) runtime.error("Use standard 1D candles; volatility uses 365 crypto trading days.") upper = ta.highest(close[1], entryN) lower = ta.lowest(close[1], exitN) regime = ta.sma(close, regimeN) logRet = math.log(close / close[1]) vol = ta.stdev(logRet, volN, true) * math.sqrt(365) weight = math.min(cap, target / math.max(vol, 0.00000001)) ready = not na(upper) and not na(lower) and not na(regime) and not na(vol) enter = ready and close > upper and close > regime leave = ready and (close < lower or close < regime) // Only submit if the following daily open lies within the evaluation window. active = time >= start and time_close < finish if barstate.isconfirmed and active and strategy.position_size == 0 and enter units = strategy.equity * weight / (close * syminfo.pointvalue) strategy.entry("Long", strategy.long, qty=units, alert_message="REGIMEBREAK BUY | simulated strategy fill") if barstate.isconfirmed and active and strategy.position_size > 0 and leave strategy.close("Long", alert_message="REGIMEBREAK SELL | simulated strategy fill") plot(regime, "Regime SMA", color=color.orange, linewidth=2) plot(upper, "Prior close high", color=color.new(color.teal, 30)) plot(lower, "Prior close low", color=color.new(color.red, 35)) plot(weight * 100, "Entry allocation %", display=display.data_window) plot(vol * 100, "Realized annual vol %", display=display.data_window)