Pulled liquidity from individual orders

How the resting book changed during each bar, from individual order events: size added and pulled on each side as a lean from -1 to 1, with a dot at every large pulled order. Without order data it falls back to the depth of book, and without depth to the tape, and it says which one it used.

//@xfscript 1
indicator("Pulled Liquidity")

let big: float = input.float(50, "big", "Pulled order size to mark", 1, 100000, 1)
let bid_color: color = input.color("#F97316", "bidColor", "Pulled bids")
let ask_color: color = input.color("#38BDF8", "askColor", "Pulled offers")

let has_orders: bool = mbo.supported() && mbo.available()
let has_depth: bool = l2.supported() && l2.available()

let added_bid: float = mbo.added_size("BUY")
let pulled_bid: float = mbo.cancelled_size("BUY")
let added_ask: float = mbo.added_size("SELL")
let pulled_ask: float = mbo.cancelled_size("SELL")
let order_lean: float = ((added_bid - pulled_bid) - (added_ask - pulled_ask)) / (added_bid + pulled_bid + added_ask + pulled_ask)
let tape_lean: float = tape.delta() / tape.volume()

let lean: float = has_orders ? order_lean : has_depth ? l2.imbalance(10) : tape_lean
plot.histogram(nz(lean, 0), "#22C55E", "#EF4444")
plot.panel_range(-1, 1)
plot.panel_hline(0, "#6B7280", "dotted", "")

for i = 0 to (has_orders ? mbo.event_count() : 0) - 1 by 1 {
  if mbo.event_type(i) == "cancel" && mbo.event_size(i) >= big {
    plot.dot(true, mbo.event_price(i), mbo.event_side(i) == "BUY" ? bid_color : ask_color, 5)
  }
}

plot.label(str.concat("LEAN FROM ", has_orders ? "ORDERS" : has_depth ? "BOOK" : "TAPE"), "#9CA3AF")

Every layer of the market, Orderflow to optionflow, on one chart.

Institutional grade Orderflow data with backtesting and journaling built in. Join the waitlist for early access.

Get Access