Advertisement
xmd79

◭ BBPCT% [AlgoAlpha]

Nov 26th, 2023
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © Algoalpha X © Sushiboi77
  3.  
  4. //@version=5
  5. indicator(shorttitle="◭ BBPCT% [AlgoAlpha]", title="◭ Bollinger Bands Percent", overlay=false)
  6.  
  7. //Symmetrical Standard Deviation Channels
  8. neon = input.bool(title = 'Neon Color Theme', defval = true)
  9. upper1 = close + 0.05 * close
  10. lower1 = close - 0.05 * close
  11. stdL = close > lower1
  12. stdS = close < upper1
  13.  
  14.  
  15. //BBPCT
  16. length = input.int(20, minval=1, group='Bollinger Band')
  17. src = input(close, title="Source", group='Bollinger Band')
  18. mult = input.float(2.0, minval=0.001, maxval=50, title="Multiplier", group='Bollinger Band')
  19. lookback = 750
  20.  
  21. showStdev = input.bool(false, title='Show Bollinger Band Stdev %', group='Settings')
  22.  
  23. var stdevArray = array.new_float(lookback,0.0)
  24.  
  25. basis = ta.sma(src, length)
  26. dev = mult * ta.stdev(src, length)
  27. upper = basis + dev
  28. lower = basis - dev
  29. positionBetweenBands = 100 * (src - lower)/(upper - lower)
  30.  
  31. array.push(stdevArray, dev/close)
  32. if array.size(stdevArray)>=lookback
  33. array.remove(stdevArray, 0)
  34.  
  35. rank = array.percentrank(stdevArray, lookback-1)
  36. hist = 100*dev/close
  37.  
  38. bullcolor = neon ? #00ffbb : #00b712
  39. bearcolor = neon ? #ff1100 : #c30010
  40.  
  41.  
  42. //PLOTS
  43. plot1 = plot(positionBetweenBands, color = color.new(color.white, 100))
  44. obupper = plot(130, color = color.new(bearcolor, 0), display = display.none)
  45. oblower = plot(110, color = color.new(bearcolor, 0), display = display.none)
  46. obmid = plot(95, display = display.none)
  47. osupper = plot(10, color = color.new(bullcolor, 30), display = display.none)
  48. oslower = plot(-10, color = color.new(bullcolor, 30), display = display.none)
  49. osmid = plot(25, color = color.new(bullcolor, 70), display = display.none)
  50. hline(50)
  51. z = plot(positionBetweenBands, "Z", positionBetweenBands > 50 ? bullcolor : bearcolor)
  52. mid = plot(50, display = display.none, editable = false)
  53.  
  54. fill(z, mid, positionBetweenBands > 50 ? positionBetweenBands : 50, positionBetweenBands > 50 ? 50 : positionBetweenBands, positionBetweenBands > 50 ? bullcolor : #00000000, positionBetweenBands > 50 ? #00000000 : bearcolor)
  55. fill(obupper, oblower, color.new(bearcolor, 80))
  56. fill (oblower, obmid, color.new(bearcolor, 87))
  57. fill(osupper, oslower, color.new(bullcolor, 87))
  58. fill(osupper, osmid, color.new(bullcolor, 93))
  59. plotshape(ta.crossover(positionBetweenBands,-8) and stdL, style = shape.triangleup, color = bullcolor, location = location.bottom, size = size.tiny)
  60. plotshape(ta.crossunder(positionBetweenBands,108) and stdS, style = shape.triangledown, color = bearcolor, location = location.top, size = size.tiny)
  61. plot(showStdev ? hist : na, style=plot.style_columns, color=(hist[1] < hist ? #26A69A : #B2DFDB) , title='Stdev %')
  62.  
  63. //Alerts
  64. alertcondition(ta.crossover(positionBetweenBands,-10), title="Bullish Reversal", message="Bullish Reversal {{exchange}}:{{ticker}}")
  65. alertcondition(ta.crossunder(positionBetweenBands,110), title="Bearish Reversal", message="Bearish Reversal {{exchange}}:{{ticker}}")
  66. alertcondition(ta.crossover(positionBetweenBands,50), title="Bullish Trend", message="Bullish Trend {{exchange}}:{{ticker}}")
  67. alertcondition(ta.crossunder(positionBetweenBands,50), title="Bearish Trend", message="Bearish Trend {{exchange}}:{{ticker}}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement