Code Library / Support/Resistance

Pine Script Dynamic S/R

Auto-detect dynamic S/R from fractal pivots.

Language: Pine Script · Category: Support/Resistance · Tags: dynamic SR, fractal, Pine Script, auto levels, TradingView

Source code

//@version=5
indicator("Dynamic S/R",overlay=true,max_lines_count=20)
pH=ta.pivothigh(high,10,10); pL=ta.pivotlow(low,10,10)
var float[] res=array.new_float(); var float[] sup=array.new_float()
if not na(pH)
    array.unshift(res,pH); if array.size(res)>5 then array.pop(res)
if not na(pL)
    array.unshift(sup,pL); if array.size(sup)>5 then array.pop(sup)

How to use this snippet

This is a building block, not a finished trading system. Paste it into your own Pine Script project, compile it, and test it on a demo account with your broker's real spreads before relying on it. You can convert it to MQL4 or MQL5 with the Pine Script converter.

Related snippets