indicator · on price · open source
Auto Support and Resistance
Running…
Loading chart…
About
Auto-detected S/R from confirmed swing highs and lows — the most recent confirmed pivot of each side becomes the active resistance (red) and support (green) line.
- Strength controls how many bars each side has to be the high/low before it's a pivot.
- Lines only update when a new pivot prints, so the chart stays clean.
- Breaks of the active R are obvious trend signals; rejections off S are mean-reversion setups.
Source code
//@version=5
indicator("Auto Support and Resistance", overlay=true)
swing = input.int(10, "Swing strength", minval=2, maxval=50)
ph = ta.pivothigh(high, swing, swing)
pl = ta.pivotlow(low, swing, swing)
lastPh = ta.valuewhen(not na(ph), ph, 0)
lastPl = ta.valuewhen(not na(pl), pl, 0)
p_R = plot(lastPh, "R", color=color.red, style=plot.style_linebr, linewidth=2)
p_S = plot(lastPl, "S", color=color.green, style=plot.style_linebr, linewidth=2)
alertcondition(ta.crossover(close, lastPh), "Resistance break", "Close crossed above the active resistance")
alertcondition(ta.crossunder(close, lastPl), "Support break", "Close crossed below the active support")
No comments yet.
Sign in to comment.