Appearance

Personalize your experience

Mode
Accent Color
Direction
MarketplacestrategiesBook Imbalance Breakout
QuaScript

Book Imbalance Breakout

Admin's ChoiceFree

Donchian breakouts taken only when the order book leans the same way

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
quascriptstrategyorder-bookbreakoutofi
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.

Book Imbalance Breakoutengine 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

Range breakouts that the order book agrees with. A Donchian breakout from OHLCV is taken only if the resting book leans the same way at the breakout bar (distance-weighted pressure beyond the threshold) and order-flow imbalance between the last books confirms it, so breakouts into a wall of opposing orders are skipped. Bars without a recorded book never trade (no guessing). Exit: ATR stop and a trailing exit at the opposite Donchian half-channel. Needs the order book (L2): backtests run only where the chart has recorded books.


Settings

Breakout channel: 30

Book pressure threshold: 0.15

Pressure decay (%): 0.25

Stop (ATR): 2


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

    • ▸ ATR stop and a trailing exit at the opposite Donchian half-channel
    • ▸ Needs the order book (L2): backtests run only where the chart has recorded books

    Source Code

    Edit in IDE
    quascript
    1strategy "Book Imbalance Breakout" {
    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/// Range breakouts that the order book agrees with. A Donchian breakout from OHLCV is taken only if
    11/// the resting book leans the same way at the breakout bar (distance-weighted pressure beyond the
    12/// threshold) and order-flow imbalance between the last books confirms it, so breakouts into a wall
    13/// of opposing orders are skipped. Bars without a recorded book never trade (no guessing).
    14/// Exit: ATR stop and a trailing exit at the opposite Donchian half-channel.
    15/// Needs the order book (L2): backtests run only where the chart has recorded books.
    16use "viz/premium" as pr
    17len = param.int(30, title = "Breakout channel", min = 5, max = 500, group = "Breakout")
    18thr = param.float(0.15, title = "Book pressure threshold", min = 0.01, max = 0.9, step = 0.01, group = "Book")
    19decay = param.float(0.25, title = "Pressure decay (%)", min = 0.02, max = 2, step = 0.01, group = "Book")
    20stop_k = param.float(2.0, title = "Stop (ATR)", min = 0.5, max = 10, step = 0.1, group = "Exit")
    21(mid, upper, lower) = ta.donchian(len)
    22(_, up_half, dn_half) = ta.donchian(len / 2)
    23pres = book.pressure(decay)
    24ofi = orderbook.ofi(5)
    25a = ta.atr(14)
    26break_up = close > upper[1]
    27break_dn = close < lower[1]
    28long_ok = break_up and pres > thr and math.coalesce(ofi, 0) >= 0
    29short_ok = break_dn and pres < -thr and math.coalesce(ofi, 0) <= 0
    30flat = position.size == 0
    31if flat and long_ok {
    32 order.market("L", side.long)
    33 exit.bracket("L stop", entry = "L", stop = close - stop_k * a)
    34}
    35if flat and short_ok {
    36 order.market("S", side.short)
    37 exit.bracket("S stop", entry = "S", stop = close + stop_k * a)
    38}
    39if position.size > 0 and close < dn_half[1] { exit.close_all() }
    40if position.size < 0 and close > up_half[1] { exit.close_all() }
    41risk.max_drawdown(25)
    42pu = render.line(upper, "Upper", color = color.translucent(color.emerald.300, 40), width = 1)
    43pd = render.line(lower, "Lower", color = color.translucent(color.rose.300, 40), width = 1)
    44render.band(pu, pd, color = pres > thr ? color.emerald.500 : pres < -thr ? color.rose.500 : color.slate.600, opacity = 0.06, title = "Range (book lean)")
    45render.mark(break_up and not long_ok, shape = shape.x, at = anchor.above_bar, color = color.amber.300, size = 0.5, title = "Breakout rejected by book")
    46render.mark(break_dn and not short_ok, shape = shape.x, at = anchor.below_bar, color = color.amber.300, size = 0.5, title = "Breakdown rejected by book")
    47render.mark(long_ok and flat, shape = shape.triangle_up, at = anchor.below_bar, color = color.emerald.300, size = 0.8, title = "Book-confirmed breakout")
    48render.mark(short_ok and flat, shape = shape.triangle_down, at = anchor.above_bar, color = color.rose.300, size = 0.8, title = "Book-confirmed breakdown")
    49 
    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.