Appearance

Personalize your experience

Mode
Accent Color
Direction
MarketplacestrategiesRegression Breakout Retest
QuaScript

Regression Breakout Retest

Free

Counter-slope channel breaks, entered on the retest of the broken edge

0.0(0)
0 installs 0 0 comments
Q
433 listings

The QuaTick team's QuaScript analyses, run by the native C++ engine.

View Profile
quascriptstrategyregressionbreakoutretest
Free
Backtest this strategy Open in QuaCode Edit in IDE
Version
Updated
Compatible

Live engine preview

QuaScriptQuaScript

The QuaScript engine's own output on the chart the terminal uses. Change the settings or edit the code and press Run to recompute it.

Regression Breakout Retestengine result
Loading the engine result…
quatick-charts · QuaScript engine on synthetic 1-minute bars · drag to pan · scroll to zoom · Run executes the script on the engine (⌘/Ctrl+Enter while editing)

About

Breaks of a clean regression channel against its own slope start new trends; the safest entry is the retest of the broken edge. A falling channel (R squared above the level) whose upper 2-sigma edge is closed through arms a long setup at that edge; when price pulls back to within the tolerance of the frozen edge and closes above it, the strategy buys. Mirror for shorts. Exit: stop below the retest low by half an ATR, target of the channel height projected from the edge, setups expire after a number of bars.


Settings

Channel window: 120

Minimum R squared: 0.55

Edge (sigma): 2

Retest tolerance (ATR): 0.3

Setup expiry (bars): 30


Backtest it yourself

Open it on the backtesting page to run it on any symbol, interval and date range, then use Monte Carlo, optimisation, walk-forward and robustness tests.

Strategy Rules

Entry Conditions

    Exit Conditions

    • ▸ stop below the retest low by half an ATR, target of the channel height projected from the edge, setups expire after a number of bars

    Source Code

    Edit in IDE
    quascript
    1strategy "Regression Breakout Retest" {
    2 overlay = true
    3 capital = 100000
    4 commission = 0.05
    5 slippage = 1
    6 sizing = risk_percent
    7 size = 1
    8 max_leverage = 1
    9}
    10/// Breaks of a clean regression channel against its own slope start new trends; the safest entry is
    11/// the retest of the broken edge. A falling channel (R squared above the level) whose upper 2-sigma
    12/// edge is closed through arms a long setup at that edge; when price pulls back to within the
    13/// tolerance of the frozen edge and closes above it, the strategy buys. Mirror for shorts.
    14/// Exit: stop below the retest low by half an ATR, target of the channel height projected from
    15/// the edge, setups expire after a number of bars.
    16use "viz/premium" as pr
    17len = param.int(120, title = "Channel window", min = 20, max = 2000, group = "Channel")
    18q_min = param.float(0.55, title = "Minimum R squared", min = 0.1, max = 0.95, step = 0.01, group = "Channel")
    19k_sd = param.float(2.0, title = "Edge (sigma)", min = 0.5, max = 4, step = 0.1, group = "Channel")
    20tol = param.float(0.3, title = "Retest tolerance (ATR)", min = 0.05, max = 2, step = 0.05, group = "Entry")
    21expiry = param.int(30, title = "Setup expiry (bars)", min = 2, max = 500, group = "Entry")
    22(v, s, _) = stat.linreg(close, len, 0)
    23sd = stat.stdev(close - v, len)
    24q = stat.r_squared(close, len)
    25a = ta.atr(14)
    26up_edge = v + k_sd * sd
    27dn_edge = v - k_sd * sd
    28persist long_lvl = na
    29persist long_h = na
    30persist long_age = 0
    31persist short_lvl = na
    32persist short_h = na
    33persist short_age = 0
    34if q[1] > q_min and s[1] < 0 and close > up_edge[1] and close[1] <= up_edge[2] {
    35 long_lvl := up_edge[1]
    36 long_h := 2 * k_sd * sd[1]
    37 long_age := 0
    38}
    39if q[1] > q_min and s[1] > 0 and close < dn_edge[1] and close[1] >= dn_edge[2] {
    40 short_lvl := dn_edge[1]
    41 short_h := 2 * k_sd * sd[1]
    42 short_age := 0
    43}
    44long_age += 1
    45short_age += 1
    46if long_age > expiry { long_lvl := na }
    47if short_age > expiry { short_lvl := na }
    48flat = position.size == 0
    49long_sig = not math.is_na(long_lvl) and long_age > 1 and low <= long_lvl + tol * a and close > long_lvl
    50short_sig = not math.is_na(short_lvl) and short_age > 1 and high >= short_lvl - tol * a and close < short_lvl
    51if flat and long_sig {
    52 order.market("L", side.long)
    53 exit.bracket("L exit", entry = "L", stop = low - 0.5 * a, target = long_lvl + long_h)
    54 long_lvl := na
    55}
    56if flat and short_sig {
    57 order.market("S", side.short)
    58 exit.bracket("S exit", entry = "S", stop = high + 0.5 * a, target = short_lvl - short_h)
    59 short_lvl := na
    60}
    61risk.max_drawdown(25)
    62pu = render.line(up_edge, "Upper edge", color = color.translucent(color.rose.300, 45), width = 1)
    63pc = render.line(v, "Regression", color = q > q_min ? (s > 0 ? color.sky.300 : color.amber.300) : color.slate.500, width = 1.5)
    64pd = render.line(dn_edge, "Lower edge", color = color.translucent(color.emerald.300, 45), width = 1)
    65render.band(pu, pd, color = color.indigo.500, opacity = 0.05, title = "Channel")
    66render.step(long_lvl, "Long retest level", color = color.emerald.300, width = 2)
    67render.step(short_lvl, "Short retest level", color = color.rose.300, width = 2)
    68render.mark(long_sig and flat, shape = shape.tag_up, at = anchor.below_bar, color = color.emerald.400, text = "Retest", title = "Retest buy")
    69render.mark(short_sig and flat, shape = shape.tag_down, at = anchor.above_bar, color = color.rose.400, text = "Retest", title = "Retest sell")
    70 
    Read-only preview. Open in QuaCode to edit and deploy.

    Reviews

    No reviews yet. Be the first to review this listing.

    Discussion

    Sign in to join the discussion. Your posts and replies show up on your profile.