Appearance
Personalize your experience
Mode
Accent Color
Direction
Queue Divergence Reversal
Admin's ChoiceFreeReversals where touch queues built against the move (order book bars only)
0.0(0)
0 installs 0 0 commentsQ
quascriptstrategyorder-bookl1reversal
Live engine preview
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.
Queue Divergence Reversalengine 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
Buys when price has fallen for several bars while the bid queue at the touch kept growing (support building) and the bar closes up; sells the mirror. Exit at a reward multiple or ATR stop. Needs the order book (L1): trades only on bars with a recorded book.
Settings
Decline bars: 4
Reward / risk: 1.5
Stop (ATR): 1.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
Source Code
Edit in IDEquascript
| 1 | strategy "Queue Divergence Reversal" { |
| 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 | /// Buys when price has fallen for several bars while the bid queue at the touch kept growing |
| 11 | /// (support building) and the bar closes up; sells the mirror. Exit at a reward multiple or ATR |
| 12 | /// stop. Needs the order book (L1): trades only on bars with a recorded book. |
| 13 | lb = param.int(4, title = "Decline bars", min = 2, max = 50) |
| 14 | rr = param.float(1.5, title = "Reward / risk", min = 0.5, max = 10, step = 0.1) |
| 15 | stopk = param.float(1.2, title = "Stop (ATR)", min = 0.2, max = 10, step = 0.1) |
| 16 | bp = book.bid |
| 17 | bq = book.bid_size |
| 18 | ap = book.ask |
| 19 | aq = book.ask_size |
| 20 | bid_flow = math.is_na(bp[1]) ? na : bp > bp[1] ? bq : bp < bp[1] ? -bq[1] : bq - bq[1] |
| 21 | ask_flow = math.is_na(ap[1]) ? na : ap < ap[1] ? aq : ap > ap[1] ? -aq[1] : aq - aq[1] |
| 22 | net = math.coalesce(bid_flow, 0) - math.coalesce(ask_flow, 0) |
| 23 | flow = stat.sum(net, lb) |
| 24 | a = ta.atr(14) |
| 25 | long_sig = not math.is_na(a) and close[1] < close[lb] and flow > 0 and close > open and not math.is_na(bp) |
| 26 | short_sig = not math.is_na(a) and close[1] > close[lb] and flow < 0 and close < open and not math.is_na(bp) |
| 27 | flat = position.size == 0 |
| 28 | if flat and long_sig { |
| 29 | order.market("L", side.long) |
| 30 | exit.bracket("L exit", entry = "L", stop = close - stopk * a, target = close + rr * stopk * a) |
| 31 | } |
| 32 | if flat and short_sig { |
| 33 | order.market("S", side.short) |
| 34 | exit.bracket("S exit", entry = "S", stop = close + stopk * a, target = close - rr * stopk * a) |
| 35 | } |
| 36 | risk.max_drawdown(25) |
| 37 | render.mark(long_sig and flat, shape = shape.triangle_up, at = anchor.below_bar, color = color.teal.300, size = 0.6, title = "Bids building") |
| 38 | render.mark(short_sig and flat, shape = shape.triangle_down, at = anchor.above_bar, color = color.rose.300, size = 0.6, title = "Asks building") |
| 39 |
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.