Advertisement
JustUncleL

BB Stoch and RSI Alert

Jan 7th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. //@version=2
  2. //
  3. study(shorttitle="BBSTORSI R1", title="BB STOCH and RSI Alert R1 by JustUncleL", overlay=true, scale=scale.right)
  4. //
  5. // Revision: R1
  6. // Original Author: JustUncleL
  7. //
  8. // * Description *
  9. // Breif: This indicator alert is a variation of the standard Bollinger Band
  10. // with RSI and Stochastic Overbought and Oversold filters.
  11. // Includes pre-warning alert conditions. Strategy and settings designed
  12. // for 1min charts and Binary Options, but could work for up to 15 min charts.
  13. //
  14. // Full: Bollinger is calculated from SMA BB(6,1.5).
  15. // RSI(9) with 75/25 Levels OB/OS boundaries
  16. // STOCH(2,3,3) with 75/25 Levels OB/OS boundaries
  17. //
  18. // Optional Market direction is calculated by two EMA (200 and 50):
  19. // When 200ema rising and 50ema above 200ema then market going up,
  20. // When 200ema falling and 60ema below 200ema then market going down.
  21. //
  22. // Potential Bollinger Breakout reversal trades identified by shapes:
  23. // The purple diamond is the pre-warning purple alert and
  24. // the green and red pointers with the PUT/CALL labels are the trade alerts.
  25. // Trade in specified direction 60sec (can also use 120sec without Martingale).
  26. //
  27. // * Notes *
  28. //
  29. // * Reference *
  30. // - This code use Bollinger calc by JayRogers in "[JR] Multi Bollinger Heat Bands - EMA/Break options"
  31. // - MA variant function from Scalp Jockey - MTF MA Cross Visual Strategizer by JayRogers
  32. // - Original idea from well know Broker's marketing youtube videos.
  33. //
  34.  
  35. // === INPUTS ===
  36. // Bollinger Bands Inputs
  37. bb_length = input(6, minval=5, title="Bollinger Length")
  38. bb_mult = input(1.5, title="Bollinger Standard Deviation", minval=0.5, maxval=10)
  39. // RSI inputs
  40. rsiLength = input(9,minval=1,title="RSI Length")
  41. rsiUpper = input(75,minval=51,maxval=99,title="RSI Upper Level")
  42. rsiLower = input(25,minval=1,maxval=49,title="RSI Lower Level")
  43. // Stoch inputs
  44. StochLen = input(2, minval=1, title="Stochtastic Length")
  45. smoothK = input(3, minval=1,title="Stoch Smooth K Length")
  46. smoothD = input(3, minval=1,title="Stoch Smooth D Length")
  47. StochUpper = input(75, minval=51,maxval=100,title="Stoch Upper Level")
  48. StochLower = input(25,minval=1,maxval=49,title="Stoch Lower Level")
  49. // MA filter inputs
  50. dFilter = input(false,title="Use Directional Filter")
  51. // Fast MA - type, length
  52. fastTyp = input(defval="EMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  53. fastLen = input(defval=50, title="Fast - Length", minval=1)
  54. // Slow MA - type, length
  55. slowTyp = input(defval="EMA", title="Slow MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
  56. slowLen = input(defval=200, title="Slow - Length", minval=1)
  57. //
  58. dCandles = input(3, minval=2, title="Candles to test Market Direction")
  59. resoln_ = input(0, minval=0, title="Candle body, how far past BB boundary in Points")
  60. // === /INPUTS ===
  61.  
  62. // === FUNCTIONS ===
  63. // Returns MA input selection variant, default to SMA if blank or typo.
  64. variant(type, src, len) =>
  65. v1 = sma(src, len) // Simple
  66. v2 = ema(src, len) // Exponential
  67. v3 = wma(src, len) // Weighted
  68. v4 = vwma(src, len) // Volume Weighted
  69. v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
  70. v6 = 2 * v2 - ema(v2, len) // Double Exponential
  71. v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
  72. v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
  73. v11 = sma(sma(src,len),len) // Triangular
  74. // SuperSmoother filter
  75. // © 2013 John F. Ehlers
  76. a1 = exp(-1.414*3.14159 / len)
  77. b1 = 2*a1*cos(1.414*3.14159 / len)
  78. c2 = b1
  79. c3 = (-a1)*a1
  80. c1 = 1 - c2 - c3
  81. v9 = c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
  82. // Zero Lag Exponential
  83. ema1 = ema(src, len)
  84. ema2 = ema(ema1, len)
  85. v10 = ema1+(ema1-ema2)
  86. // return variant, defaults to SMA if input invalid.
  87. type=="EMA"?v2 : type=="WMA"?v3 : type=="VWMA"?v4 : type=="SMMA"?v5 : type=="DEMA"?v6 : type=="TEMA"?v7 : type=="HullMA"?v8 : type=="SSMA"?v9 : type=="ZEMA"?v10 : type=="TMA"? v11: v1
  88.  
  89. // === /FUNCTIONS ===
  90.  
  91. // === SERIES ===
  92. // Calculation for EMAs and market direction.
  93. SlowEMA = variant(slowTyp, close, slowLen)
  94. FastEMA = variant(slowTyp, close, fastLen)
  95. mDirection = rising(SlowEMA,dCandles) and FastEMA>SlowEMA ? +1 : falling(SlowEMA,dCandles) and FastEMA<SlowEMA ? -1 : 0
  96.  
  97. // Get point value
  98. point = syminfo.mintick
  99. resoln = point * resoln_
  100.  
  101. //
  102. // calculate current rsi value
  103. rsiVal = rsi(close, rsiLength)
  104.  
  105. // Calculate Bollinger Bands Deviation
  106. bb_basis = sma(close, bb_length)
  107. dev = stdev(close, bb_length)
  108. bb_dev = bb_mult * dev
  109. // Upper band
  110. bb_high = bb_basis + bb_dev
  111. // Lower Band
  112. bb_low = bb_basis - bb_dev
  113.  
  114. // get Stoch values
  115. StochK = sma(stoch(close, high, low, StochLen), smoothK)
  116. StochD = sma(StochK, smoothD)
  117.  
  118. // === /SERIES ===
  119.  
  120. // === PLOTTING ===
  121.  
  122. // plot MAs
  123. plot(SlowEMA, title="SlowEMA", style=line, linewidth=2, color=red)
  124. plot(FastEMA, title="FastEMA", style=line, linewidth=2, color=olive)
  125.  
  126. // --- Plot Bollinger Bands
  127. // plot basis
  128. plot(bb_basis, title="Basis Line", color=navy, transp=50)
  129. // plot and fill upper bands
  130. ubo = plot(bb_high, title="Upper Band Outer", color=blue, transp=20)
  131. lbo = plot(bb_low, title="Lower Band Outer", color=blue, transp=20)
  132. fill(ubo, lbo, title="Center Channel Fill", color=gray, transp=80)
  133.  
  134. // Is RSI and Stoch OB or OS
  135. inRange = (rsiVal<rsiLower or rsiVal>rsiUpper) and (StochK<StochLower or StochK>StochUpper) and (StochD<StochLower or StochD>StochUpper)
  136.  
  137. // Is this a breakout warning signal? this rebuilds until candle closed
  138. FastWarn_hi = ((close>open) and (not dFilter or (mDirection<0 and close<SlowEMA))) ? inRange and (close > bb_high+resoln) : false
  139. FastWarn_lo = ((close<open) and (not dFilter or (mDirection>0 and close>SlowEMA))) ? inRange and (close < bb_low-resoln) : false
  140.  
  141. // Do we have a breakout signal?
  142. FastBreak_hi = ((not dFilter or (mDirection<0 and close<SlowEMA)) and FastWarn_hi[1] and (not FastWarn_hi)) ? inRange and (close[1] >= bb_high[1]+resoln) : false
  143. FastBreak_lo = ((not dFilter or (mDirection>0 and close>SlowEMA)) and FastWarn_lo[1] and (not FastWarn_lo)) ? inRange and (close[1] <= bb_low[1]-resoln) : false
  144.  
  145. // Generate alert condition
  146. bbAlert = FastWarn_hi or FastWarn_lo
  147. alertcondition(bbAlert, title="BBRSI Alert", message="BBRSI Trade Alert")
  148.  
  149. // plot breakouts and create alert condition
  150. plotshape(FastWarn_hi, title="BB High Warning", style=shape.diamond, location=location.abovebar, size=size.tiny, color=fuchsia, transp=0)
  151. plotshape(FastWarn_lo, title="BB Low Warning", style=shape.diamond, location=location.belowbar, size=size.tiny, color=fuchsia, transp=0)
  152. //
  153. plotshape(FastBreak_hi, title="BB High Alert", style=shape.triangledown, location=location.abovebar, text="PUT", size=size.small, color=red, transp=0)
  154. plotshape(FastBreak_lo, title="BB Low Alert", style=shape.triangleup, location=location.belowbar, text="CALL", size=size.small, color=green, transp=0)
  155.  
  156. // draw background bar to highlight
  157. Highlight = (FastWarn_hi or FastWarn_lo) ? fuchsia : FastBreak_hi ? red : FastBreak_lo ? green : na
  158. bgcolor(Highlight, transp=75)
  159.  
  160. // === /PLOTTING ===
  161.  
  162. //
  163. //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement