Appearance

Personalize your experience

Mode
Accent Color
Direction
MarketplacestrategiesMicroprice Momentum
QuaScript

Microprice Momentum

Free

Intraday: microprice lean + order-flow imbalance on a cheap spread

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-bookmicropriceintraday
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.

Microprice Momentumengine 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

A short-horizon strategy for intraday charts. It goes with the side the book is about to give way on: the microprice leaning beyond a fraction of the spread, cumulative order-flow imbalance of the top levels positive (negative) over the last bars, and the bar itself closing in its upper (lower) half on rising volume. Trades only when the spread is cheap against the bar range, so the edge is not eaten by crossing the spread. Exit: after a few bars, on an opposite signal, or on an ATR stop. Needs the order book (L1 for the microprice, L2 for order-flow imbalance).


Settings

Microprice edge (spreads): 0.15

OFI bars: 5

Max spread (x ATR): 0.1

Bars held: 5

Stop (ATR): 1.5


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

    • ▸ after a few bars, on an opposite signal, or on an ATR stop
    • ▸ Needs the order book (L1 for the microprice, L2 for order-flow imbalance)

    Source Code

    Edit in IDE
    quascript
    1strategy "Microprice Momentum" {
    2 overlay = true
    3 capital = 100000
    4 commission = 0.02
    5 slippage = 1
    6 sizing = percent_equity
    7 size = 20
    8 max_leverage = 1
    9}
    10/// A short-horizon strategy for intraday charts. It goes with the side the book is about to give
    11/// way on: the microprice leaning beyond a fraction of the spread, cumulative order-flow imbalance
    12/// of the top levels positive (negative) over the last bars, and the bar itself closing in its
    13/// upper (lower) half on rising volume. Trades only when the spread is cheap against the bar range,
    14/// so the edge is not eaten by crossing the spread.
    15/// Exit: after a few bars, on an opposite signal, or on an ATR stop.
    16/// Needs the order book (L1 for the microprice, L2 for order-flow imbalance).
    17edge_min = param.float(0.15, title = "Microprice edge (spreads)", min = 0.02, max = 0.5, step = 0.01, group = "Book")
    18ofi_len = param.int(5, title = "OFI bars", min = 1, max = 100, group = "Book")
    19max_sp = param.float(0.1, title = "Max spread (x ATR)", min = 0.005, max = 1, step = 0.005, group = "Book")
    20hold = param.int(5, title = "Bars held", min = 1, max = 100, group = "Exit")
    21stop_k = param.float(1.5, title = "Stop (ATR)", min = 0.2, max = 10, step = 0.1, group = "Exit")
    22a = ta.atr(14)
    23edge = (book.microprice - book.mid) / math.max(book.spread, 1e-12)
    24ofi_sum = stat.sum(math.coalesce(orderbook.ofi(5), 0), ofi_len)
    25clv = ((close - low) - (high - close)) / math.max(high - low, 1e-12)
    26cheap = book.spread < max_sp * a
    27vol_up = volume > ta.sma(volume, 20)
    28long_sig = cheap and edge > edge_min and ofi_sum > 0 and clv > 0 and vol_up
    29short_sig = cheap and edge < -edge_min and ofi_sum < 0 and clv < 0 and vol_up
    30flat = position.size == 0
    31if flat and long_sig {
    32 order.market("L", side.long)
    33 exit.bracket("L stop", entry = "L", stop = close - stop_k * a)
    34}
    35if flat and short_sig {
    36 order.market("S", side.short)
    37 exit.bracket("S stop", entry = "S", stop = close + stop_k * a)
    38}
    39if (position.size > 0 and (short_sig or position.bars_held >= hold)) or (position.size < 0 and (long_sig or position.bars_held >= hold)) { exit.close_all() }
    40risk.max_drawdown(20)
    41render.line(book.microprice, "Microprice", color = color.translucent(color.cyan.300, 30), width = 1)
    42render.mark(long_sig and flat, shape = shape.triangle_up, at = anchor.below_bar, color = color.cyan.300, size = 0.6, title = "Book momentum long")
    43render.mark(short_sig and flat, shape = shape.triangle_down, at = anchor.above_bar, color = color.pink.300, size = 0.6, title = "Book momentum short")
    44 
    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.