strategy · own pane · open source

IBS Mean Reversion strategy

IBS Mean Reversion is a free open-source strategy by @deepwick. Internal Bar Strength mean reversion, from the paper Using Internal Bar Strength as a Key… Deepwick Script runs a subset of Pine Script.

Deepwick · @deepwickv1Updated 3 Nov 2026▲ 0 users
Running…
Loading chart…

What IBS Mean Reversion does

Internal Bar Strength mean reversion, from the paper Using Internal Bar Strength as a Key Indicator for Trading Country ETFs (arXiv:2306.12434). IBS measures where the close sits inside the bar's range: (close - low) / (high - low), from 0 (closed on the low) to 1 (closed on the high).

  • Buy below 0.2 (the bar was rejected at its low) and sell above 0.8 (closed on the high).
  • The paper measures the next-day return as ~0.54-0.61 positive after IBS < 0.2, against ~0.46-0.52 after IBS > 0.8.
  • Holds for one day: the paper shows performance degrades with longer holding periods.
  • Caveat from the paper: IBS is computed at the close and entered at the close, which is hard in practice and costs slippage. The short side also pays a borrow rate that erodes the edge.

Source code

Deepwick Script, a subset of Pine Script · read-only

//@version=6
strategy("IBS Mean Reversion", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
buyBelow = input.float(0.2, "Buy below IBS", minval=0.05, maxval=0.45, step=0.05)
sellAbove = input.float(0.8, "Sell above IBS", minval=0.55, maxval=0.95, step=0.05)
allowShort = input.bool(true, "Allow shorts")
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorLine = input.color("color.blue", "Color  Line")
colorUp = input.color("color.green", "Color  Up")
colorDown = input.color("color.red", "Color  Down")
colorNeutral = input.color("color.gray", "Color  Neutral")
ibs = (close - low) / (high - low)
longSignal = strategy.position_size == 0 and ibs < buyBelow
shortSignal = strategy.position_size == 0 and allowShort and ibs > sellAbove
exitSignal = strategy.position_size != 0
if longSignal
    strategy.entry("Long", strategy.long)
if shortSignal
    strategy.entry("Short", strategy.short)
if strategy.position_size > 0
    strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
    strategy.close_all("IBS exit")
hline(0.8, "Sell zone", color=colorNeutral, linestyle=hline.style_dashed)
hline(0.2, "Buy zone", color=colorNeutral, linestyle=hline.style_dashed)
p_IBS = plot(ibs, "IBS", color=colorLine, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(shortSignal, "Short", style=shape.triangledown, location=location.abovebar, color=colorDown, text="S")
alertcondition(longSignal, "IBS long entry", "Close was rejected near the bar low")
alertcondition(shortSignal, "IBS short entry", "Close landed near the bar high")

Comments

No comments yet.

Sign in to comment.