strategy · own pane · open source

ROC Breakout

Deepwick · @deepwickv1Updated 2 Oct 2026▲ 0 users
Running…
Loading chart…

About

Rate of Change momentum strategy: enter when the rate of change over Length bars crosses above Threshold (default 0), exit when it falls back below.

  • A higher threshold filters for stronger momentum bursts.
  • Combine with a trend filter (e.g. close > 200 SMA) for swing trading.
  • 10-period ROC is the textbook momentum window.

Source code

//@version=5
strategy("ROC Breakout", 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)
len = input.int(10, "ROC Length", minval=5, maxval=100, step=1)
threshold = input.float(0, "ROC Threshold", minval=-20, maxval=20, step=0.1)
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)
r = ta.roc(close, len)
longSignal = strategy.position_size == 0 and ta.crossover(r, threshold)
exitSignal = strategy.position_size > 0 and ta.crossunder(r, threshold)
if longSignal
    strategy.entry("Long", strategy.long)
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("Long", comment="ROC exit")
hline(0, "Zero", color=color.gray, linestyle=hline.style_dotted)
p_ROC = plot(r, "ROC", color=color.blue, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=color.green, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=color.red, text="X")
alertcondition(longSignal, "ROC long entry", "ROC crossed above threshold")
alertcondition(exitSignal, "ROC exit", "ROC crossed below threshold")

Comments

No comments yet.

Sign in to comment.