Examples
Absorption pattern with explanations
An absorption definition written as a pattern: at each trade, the price it hits is examined over a window. The pattern emits a signal (a diamond on the chart) with a text explaining which conditions held and with what values. Every threshold is a setting, and the volume threshold is a rank.
indicator "Absorption — my definition" { overlay: true, level_history: 2m }
win = input.duration("Window", 30s)
minRank = input.float("Min aggressor volume rank", 97, min: 0, max: 100, group: "Thresholds")
normWin = input.duration("Normalize over", 30m, group: "Thresholds")
heldPct = input.float("Held at best (% of window)", 60, min: 0, max: 100, group: "Thresholds")
maxMove = input.int("Max price move (ticks)", 2, min: 0, group: "Thresholds")
pattern "Absorption" {
on: trade
// buyers lifting an offer that holds = sellers absorbing: a "sell" signal
side: trade.is_buy ? "sell" : "buy"
cooldown: win
show: [lv.aggressor_volume, lv.added, lv.displayed]
lv = mbo.level(trade.price, window: win)
// normalized at every trade, before the other conditions
rk = norm.rank(na(lv) ? na : lv.aggressor_volume, normWin, min_count: 200)
moved = abs(trade.price - open) / instrument.tick
when not na(lv)
and rk >= minRank
and lv.time_at_best >= win * heldPct / 100
and lv.displayed > 0
and moved <= maxMove
}
on signal(s from "Absorption") {
label.new(s.time, s.price, s.side == "sell" ? "offer holds" : "bid holds", color: s.side == "sell" ? #ef5350 : #26a69a)
}What to notice:
- the event variable of
on: tradeistrade; norm.rankis computed beforewhen, at every trade; anavalue is not added to the population;- the explanation attached to each signal lists every
andterm with its values, then theshow:values; level_history: 2mkeeps enough per-price history for windows up to 2 minutes.