xmd79

Pivot Point SuperTrend

Jun 2nd, 2023
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © team_shivkaran
  3.  
  4. //@version=4
  5. study("Pivot Point SuperTrend", overlay = true)
  6. prd = input(defval = 2, title="Pivot Point Period", minval = 1, maxval = 50)
  7. Factor=input(defval = 3, title = "ATR Factor", minval = 1, step = 0.1)
  8. Pd=input(defval = 10, title = "ATR Period", minval=1)
  9. showpivot = input(defval = false, title="Show Pivot Points")
  10. showlabel = input(defval = true, title="Show Buy/Sell Labels")
  11. showcl = input(defval = false, title="Show PP Center Line")
  12. showsr = input(defval = false, title="Show Support/Resistance")
  13.  
  14. // get Pivot High/Low
  15. float ph = pivothigh(prd, prd)
  16. float pl = pivotlow(prd, prd)
  17.  
  18. // drawl Pivot Points if "showpivot" is enabled
  19. plotshape(ph and showpivot, text="H", style=shape.labeldown, color=na, textcolor=color.rgb(34, 34, 34), location=location.abovebar, transp=0, offset = -prd)
  20. plotshape(pl and showpivot, text="L", style=shape.labeldown, color=na, textcolor=color.rgb(5,151,127), location=location.belowbar, transp=0, offset = -prd)
  21.  
  22. // calculate the Center line using pivot points
  23. var float center = na
  24. float lastpp = ph ? ph : pl ? pl : na
  25. if lastpp
  26. if na(center)
  27. center := lastpp
  28. else
  29. //weighted calculation
  30. center := (center * 2 + lastpp) / 3
  31.  
  32. // upper/lower bands calculation
  33. Up = center - (Factor * atr(Pd))
  34. Dn = center + (Factor * atr(Pd))
  35.  
  36. // get the trend
  37. float TUp = na
  38. float TDown = na
  39. Trend = 0
  40. TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : Up
  41. TDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : Dn
  42. Trend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)
  43. Trailingsl = Trend == 1 ? TUp : TDown
  44.  
  45. // plot the trend
  46. linecolor = Trend == 1 and nz(Trend[1]) == 1 ? color.lime : Trend == -1 and nz(Trend[1]) == -1 ? color.red : na
  47. plot(Trailingsl, color = linecolor , linewidth = 2, title = "PP SuperTrend")
  48.  
  49. plot(showcl ? center : na, color = showcl ? center < hl2 ? color.blue : color.red : na)
  50.  
  51. // check and plot the signals
  52. bsignal = Trend == 1 and Trend[1] == -1
  53. ssignal = Trend == -1 and Trend[1] == 1
  54. plotshape(bsignal and showlabel ? Trailingsl : na, title="Buy", text="Buy", location = location.absolute, style = shape.labelup, size = size.tiny, color = color.lime, textcolor = color.black, transp = 0)
  55. plotshape(ssignal and showlabel ? Trailingsl : na, title="Sell", text="Sell", location = location.absolute, style = shape.labeldown, size = size.tiny, color = color.red, textcolor = color.white, transp = 0)
  56.  
  57. //get S/R levels using Pivot Points
  58. float resistance = na
  59. float support = na
  60. support := pl ? pl : support[1]
  61. resistance := ph ? ph : resistance[1]
  62.  
  63. // if enabled then show S/R levels
  64. plot(showsr and support ? support : na, color = showsr and support ? color.lime : na, style = plot.style_circles, offset = -prd)
  65. plot(showsr and resistance ? resistance : na, color = showsr and resistance ? color.red : na, style = plot.style_circles, offset = -prd)
  66.  
  67. // alerts
  68. alertcondition(Trend == 1 and Trend[1] == -1, title='Buy Signal', message='Buy Signal')
  69. alertcondition(Trend == -1 and Trend[1] == 1, title='Sell Signal', message='Sell Signal')
  70. alertcondition(change(Trend), title='Trend Changed', message='Trend Changed')
  71.  
Advertisement
Add Comment
Please, Sign In to add comment