Examples
Large orders pulled before price reaches them
A large resting order that never trades and disappears as price comes near is a classic reason to distrust displayed size. This script inspects every cancel: the order's size, its age, whether it was ever filled, and how close price was when it left.
indicator "Pulled before touch" { overlay: true }
minSize = input.int("Min size", 100, min: 1)
minAge = input.duration("Min age", 2s)
maxTicks = input.int("Price within (ticks)", 4, min: 1)
state filledIds = map() // ids of orders that traded at least once
on order(o) {
if o.is_fill { filledIds[o.id] = true }
if o.is_cancel and o.previous_size >= minSize and o.age >= minAge and not filledIds.has(o.id) {
// distance between the canceled order and the opposite best price (where trades happen)
best = o.side == "bid" ? mbo.best_ask : mbo.best_bid
if not na(best) {
dist = abs(best - o.price) / instrument.tick
if dist <= maxTicks and dist >= 1 {
label.new(o.time, o.price, "pulled " + str(o.previous_size) + " at " + str(dist) + "t", color: #ffb300)
}
}
}
// forget an order only once nothing of it is left in the book
if (o.is_cancel or o.is_fill) and na(mbo.order(o.id)) { filledIds.remove(o.id) }
}What to notice:
o.previous_sizeis the order's size before the cancel,o.ageits age since it was added;- the script keeps its own memory of filled ids; without it, an order partly filled and then canceled would look like a spoof. An id is removed only when the order has fully left the book (
mbo.order(o.id)isna): whenon orderruns, the book already includes the event, so a partial fill or a partial cancel leaves the order, and its memory, in place; - the shipped definition
strate/patterns/spoofing_pulled_before_touchis another, more complete take on the same idea.