Advertisement
Guest User

bbm

a guest
Jul 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. //@version=3
  2. study(shorttitle="BBm", title='overlay', overlay=true)
  3. ma_type = input(defval='SMA', type=string, options=['SMA', 'Double SMA', 'Triple SMA', 'EMA', 'Double EMA', 'Triple EMA', 'HMA'])
  4. ma_src = input(close)
  5. ma_01_length = input(20)
  6. //sma_02_length = input(200)
  7. fractal_size = input(2)
  8.  
  9. f_ma(_type, _src, _length)=>
  10. _ma = 0.0
  11. if _type == 'SMA'
  12. _ma := sma(_src, _length)
  13. if _type == 'Double SMA'
  14. _ma := sma(sma(_src, _length), _length)
  15. if _type == 'Triple SMA'
  16. _ma := sma(sma(sma(_src, _length), _length), _length)
  17. if _type == 'EMA'
  18. _ma := ema(_src, _length)
  19. if _type == 'Double EMA'
  20. _ma := ema(ema(_src, _length), _length)
  21. if _type == 'Triple EMA'
  22. _ma := ema(ema(ema(_src, _length), _length), _length)
  23. _return = _ma
  24.  
  25. ma_01 = f_ma(ma_type, ma_src, ma_01_length)
  26. //sma_02 = sma(sma_src, sma_02_length)
  27.  
  28. //-------------------------------------------
  29. sleeve_ma_type = input(defval='SMA', type=string, options=['SMA', 'Double SMA', 'Triple SMA', 'EMA', 'Double EMA', 'Triple EMA', 'HMA'])
  30. sleeve_src = input(close)
  31. sleeve_01_length = input(5)
  32. sleeve_02_length = input(10)
  33.  
  34. sleeve_01 = f_ma(sleeve_ma_type, sleeve_src, sleeve_01_length)
  35. sleeve_02 = f_ma(sleeve_ma_type, sleeve_src, sleeve_02_length)
  36. //--------------------------------------------
  37. atr_length = input(100)
  38. atr = atr(atr_length)
  39. atr_deviation = atr * input(2.618)
  40. atr_smoothing_length = input(1)
  41.  
  42. f_atr_stop(_deviation, _length)=>
  43. _stop = close
  44. _stop := nz(_stop[1], close)
  45. if close > _stop
  46. _stop := max(_stop, close - _deviation)
  47. if close < _stop
  48. _stop := min(_stop, close + _deviation)
  49. _return = ema(_stop, _length)
  50.  
  51.  
  52. stop = f_atr_stop(atr_deviation, atr_smoothing_length)
  53.  
  54. up_1 = stop + atr_deviation + (atr * 0)
  55. do_1 = stop - atr_deviation - (atr * 0)
  56.  
  57. //--------------------------------------------
  58. h = pivothigh(high, fractal_size, fractal_size)
  59. l = pivotlow(low, fractal_size, fractal_size)
  60. //--------------------------------------------
  61. plotcandle(high, high, low, high, title='Candles', color=black, show_last=2)
  62. plotcandle(low, high, low, low, title='Candles', color=black, show_last=2)
  63.  
  64. plot(series=stop, title='ATR AVG', color=black)
  65. plot(series=up_1, title='ATR Upper', color=black, transp=0)
  66. plot(series=do_1, title='ATR Lower', color=black, transp=0)
  67.  
  68. plot(series=h, title='H', color=black, linewidth=2, style=cross, transp=0, offset=-fractal_size)
  69. plot(series=l, title='L', color=black, linewidth=2, style=cross, transp=0, offset=-fractal_size)
  70. //plotshape(series=h, title='H', style=shape.triangleup, location=location.absolute, color=black, transp=0, offset=-fractal_size)
  71. //plotshape(series=l, title='L', style=shape.triangledown, location=location.absolute, color=black, transp=0, offset=-fractal_size)
  72. ma_color = ma_src > ma_01 ? #2d862d : #993333
  73. m1 = plot(series=ma_01, title='SMA 1', color=ma_color, linewidth=2, transp=0)
  74. //m2 = plot(series=sma_02, title='SMA 2', color=navy, linewidth=2, transp=0)
  75.  
  76. s0 = plot(series=sleeve_src, title='S', color=black, transp=0)
  77. plot(series=sleeve_src[1], title='S', color=black, style=circles, linewidth=1, transp=0, show_last=1)
  78. plot(series=sleeve_src, title='S', color=black, style=circles, linewidth=2, transp=0, show_last=1)
  79. s1 = plot(series=sleeve_01, title='S', color=black, transp=60)
  80. s2 = plot(series=sleeve_02, title='S', color=black, transp=80)
  81.  
  82. fill(plot1=m1, plot2=s2, color=sleeve_02 > ma_01 ? #ffffe6 : #e6e6ff, transp=50, title='Sleeve')
  83. fill(plot1=s0, plot2=s2, color=#bfbfbf, transp=50, title='Sleeve')
  84. fill(plot1=s0, plot2=s1, color=#999999, transp=50, title='Sleeve')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement