xmd79

Filter out Weak pivot highs/lows

May 22nd, 2023
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. //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.
  2. // © twingall
  3.  
  4. //@version=5
  5. indicator("Filter out Weak pivot highs/lows", overlay = true)
  6. lb =input.int(15, 'pivots: lookback/forward', group = 'Pivots highs & lows', tooltip = "larger number for more significant pivot highs / pivot lows")
  7. 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")
  8. 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")
  9. 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")
  10. int x = confirmOnClose?1:0
  11.  
  12. //Pivot highs & Pivot lows: filtering out the rounded/unimpressive pivot highs
  13. pivHigh = ta.pivothigh(high, lb, lb)
  14. isPivHigh = na(pivHigh)? false:true
  15. atr = ta.atr(2*lb)
  16. maH = ta.sma(high, 2*lb)
  17. bool spikyH = useSpikeyCond?pivHigh > maH+atrMult*atr:true //where atrMult = 1.5 seems optimal when using lb = 15
  18. var float ph = 0 //for alerts
  19. if isPivHigh[x]
  20. if spikyH[x]
  21. ph:=pivHigh[x]
  22. label.new(bar_index-(lb+x), high[lb+x], text ="piv High",color=color.new(color.blue,50))
  23.  
  24. pivLow = ta.pivotlow(low, lb, lb)
  25. isPivLow = na(pivLow)? false:true
  26. maL = ta.sma(low, 2*lb)
  27. bool spikyL = useSpikeyCond? pivLow < maL-atrMult*atr:true //where atrMult = 1.5 seems optimal when using lb = 15
  28.  
  29. var float pl = 0 //for alerts
  30. if isPivLow[x]
  31. if spikyL[x]
  32. pl:=pivLow[x]
  33. label.new(bar_index-(lb+x), low[lb+x], text ="piv Low", style = label.style_label_up, color = color.new(color.blue,50))
  34.  
  35. //alert conditions: need to be manually set from indicator status line.
  36. //will alert on sweep of most recent (freshly painted) Pivot high or low.
  37. //alert based on settings of indicator at the time of setting the alert
  38. 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
  39. 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
  40. 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
  41. 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