Examples

Book pressure and microprice

Aggregated book snapshots (every 250 ms) summarized per bar: the depth imbalance over the first levels and the distance between the microprice and the mid, both sampled once per second by a clock and averaged.

StrateScript
indicator "Book pressure" { overlay: false, min: -1, max: 1, precision: 2 }

levels = input.int("Levels", 5, min: 1, max: 300)

clock sec = clock.time(1s)
state imbSum = 0
state microSum = 0
state n = 0

on clock sec {
  if book.available and book.spread > 0 {
    imbSum += book.imbalance(levels)
    microSum += (book.microprice - book.mid) / book.spread
    n += 1
  }
}

plot(n > 0 ? imbSum / n : na, #2962ff, title: "Depth imbalance", width: 2)
plot(n > 0 ? microSum / n : na, #e8c15a, title: "Microprice − mid (in spreads)")
hline(0, color: #888888)

imbSum = 0
microSum = 0
n = 0

What to notice:

STRATE / PRODUCT SCREENSHOT

Actual platform screenshot.