strategy · on price · open source
Pivot Bounce Strategy
Running…
Loading chart…
About
Pivot Bounce trend strategy: long when price breaks above the most recent confirmed swing-high pivot (with two consecutive pivots agreeing), exit on the reverse.
- Pivots are confirmed
rightbars later, so signals never repaint. - Combine with a higher-timeframe trend for cleaner entries.
- Use as a breakout filter for any oscillator setup.
Source code
//@version=5
strategy("Pivot Bounce Strategy", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
pivotLen = input.int(10, "Pivot Length", minval=5, maxval=50, step=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)
ph = ta.pivothigh(high, pivotLen, pivotLen)
pl = ta.pivotlow(low, pivotLen, pivotLen)
lastPH = ta.valuewhen(not na(ph), ph[pivotLen], 0)
prevPH = ta.valuewhen(not na(ph), ph[pivotLen], 1)
longSignal = strategy.position_size == 0 and not na(lastPH) and not na(prevPH) and lastPH > prevPH and close > lastPH
exitSignal = strategy.position_size > 0 and not na(pl) and close < pl[pivotLen]
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="Pivot break down")
p_Pivot_High = plot(lastPH, "Pivot High", color=color.orange, style=plot.style_linebr, linewidth=1)
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, "Pivot bounce long entry", "Price broke above rising pivot high")
alertcondition(exitSignal, "Pivot exit", "Price broke below recent pivot low")
No comments yet.
Sign in to comment.