// overlay = true
const volMult = input.float("Volume multiplier", 1.5, { min: 1.0, max: 5.0, step: 0.1 });
const volLen = input.int("Volume MA length", 20, { min: 5 });
const bullColor = input.color("Bullish OB color", "#22c55e25");
const bearColor = input.color("Bearish OB color", "#ef444425");
const bullBorder = input.color("Bullish border", "#22c55eFF");
const bearBorder = input.color("Bearish border", "#ef4444FF");
const mitColor = input.color("Mitigated color", "#6b728040");
onBar(() => {
const vol = ctx.volume();
const volMa = ta.sma(ctx.volume, volLen);
const isHighVol = !na(volMa) && vol > volMa * volMult;
const prevBear = ctx.open(1) > ctx.close(1);
const prevBull = ctx.open(1) < ctx.close(1);
const curBull = ctx.close() > ctx.open();
const curBear = ctx.close() < ctx.open();
const bullEngulf = prevBear && curBull && ctx.close() > ctx.open(1) && isHighVol;
const bearEngulf = prevBull && curBear && ctx.close() < ctx.open(1) && isHighVol;
const prevBar = ctx.i() - 1;
if (bullEngulf) {
Box(`bull_ob_${prevBar}`, {
x1: prevBar, y1: ctx.low(1),
x2: ctx.i() + 1, y2: ctx.open(1),
color: bullColor,
borderColor: bullBorder,
borderWidth: 1,
extend: "right",
text: "Bull OB",
textColor: bullBorder,
textSize: "xs",
textHAlign: "left",
textVAlign: "top",
});
}
if (bearEngulf) {
Box(`bear_ob_${prevBar}`, {
x1: prevBar, y1: ctx.open(1),
x2: ctx.i() + 1, y2: ctx.high(1),
color: bearColor,
borderColor: bearBorder,
borderWidth: 1,
extend: "right",
text: "Bear OB",
textColor: bearBorder,
textSize: "xs",
textHAlign: "left",
textVAlign: "top",
});
}
// Mitigation: fade boxes that price has traded through
// (Simplified: check if current close is inside any recent box)
// For a production indicator, track active OB levels in Series
});