Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Just a method for refining Pivot highs/lows (ta.pivothigh() and ta.pivotlow()); allowing one to get a closer approximation of what would catch the eye as an obvious swing high/low.
- // © twingall
- //@version=5
- indicator("Filter out Weak pivot highs/lows", overlay = true)
- lb =input.int(15, 'pivots: lookback/forward', group = 'Pivots highs & lows', tooltip = "larger number for more significant pivot highs / pivot lows")
- atrMult =input.float(1.5, "Spikeyness Index", minval = 0, step =0.1, inline ='2', group = 'Pivots highs & lows', tooltip = "For catching only the 'spikier' pivot highs/pivot lows\n\nSetting to =0 will effectively remove this condition and plot standard pivot highs/lows\n\nIncreasing this number will filter out smooth/unimpressive pivot high&lows\n\nRepresents local ATR multiple for distance from local Moving average a high or low must be\n\nSetting of 1.5 seems optimal on 15m chart with pivot lookback/lookforward = 15")
- useSpikeyCond =input.bool(true, "use spikey condition", inline ='3',group = 'Pivots highs & lows', tooltip ="toggle off to see how typical pivots are painted; to notice the difference/improvement")
- confirmOnClose = input.bool(true, "wait 1x bar to confirm (avoid repainting)", inline ='4',group = 'Pivots highs & lows', tooltip = "default is ON, waits for realtime bar to close before confirming Pivot H/L\n\nToggle this off to get Pivot highs confirmed one bar earlier, but at the cost of sometimes causing repainting")
- int x = confirmOnClose?1:0
- //Pivot highs & Pivot lows: filtering out the rounded/unimpressive pivot highs
- pivHigh = ta.pivothigh(high, lb, lb)
- isPivHigh = na(pivHigh)? false:true
- atr = ta.atr(2*lb)
- maH = ta.sma(high, 2*lb)
- bool spikyH = useSpikeyCond?pivHigh > maH+atrMult*atr:true //where atrMult = 1.5 seems optimal when using lb = 15
- var float ph = 0 //for alerts
- if isPivHigh[x]
- if spikyH[x]
- ph:=pivHigh[x]
- label.new(bar_index-(lb+x), high[lb+x], text ="piv High",color=color.new(color.blue,50))
- pivLow = ta.pivotlow(low, lb, lb)
- isPivLow = na(pivLow)? false:true
- maL = ta.sma(low, 2*lb)
- bool spikyL = useSpikeyCond? pivLow < maL-atrMult*atr:true //where atrMult = 1.5 seems optimal when using lb = 15
- var float pl = 0 //for alerts
- if isPivLow[x]
- if spikyL[x]
- pl:=pivLow[x]
- label.new(bar_index-(lb+x), low[lb+x], text ="piv Low", style = label.style_label_up, color = color.new(color.blue,50))
- //alert conditions: need to be manually set from indicator status line.
- //will alert on sweep of most recent (freshly painted) Pivot high or low.
- //alert based on settings of indicator at the time of setting the alert
- alertcondition(close >ph , title='Pivot high sweep', message='Pivot high swept') //note that the high of a realtime bar is treated as 'close', so we use close
- alertcondition(close <pl, title='Pivot low sweep', message='Pivot low swept') //note that the low of a realtime bar is treated as 'close', so we use close
- alertcondition(isPivHigh[x] and spikyH[x], title='Pivot High confirmed', message='Pivot high confirmed') //note that the high of a realtime bar is treated as 'close', so we use close
- alertcondition(isPivLow[x] and spikyL[x], title='Pivot Low confirmed', message='Pivot low confirmed') //note that the low of a realtime bar is treated as 'close', so we use close
Advertisement
Add Comment
Please, Sign In to add comment