Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- //
- study(shorttitle="BBSTORSI R1", title="BB STOCH and RSI Alert R1 by JustUncleL", overlay=true, scale=scale.right)
- //
- // Revision: R1
- // Original Author: JustUncleL
- //
- // * Description *
- // Breif: This indicator alert is a variation of the standard Bollinger Band
- // with RSI and Stochastic Overbought and Oversold filters.
- // Includes pre-warning alert conditions. Strategy and settings designed
- // for 1min charts and Binary Options, but could work for up to 15 min charts.
- //
- // Full: Bollinger is calculated from SMA BB(6,1.5).
- // RSI(9) with 75/25 Levels OB/OS boundaries
- // STOCH(2,3,3) with 75/25 Levels OB/OS boundaries
- //
- // Optional Market direction is calculated by two EMA (200 and 50):
- // When 200ema rising and 50ema above 200ema then market going up,
- // When 200ema falling and 60ema below 200ema then market going down.
- //
- // Potential Bollinger Breakout reversal trades identified by shapes:
- // The purple diamond is the pre-warning purple alert and
- // the green and red pointers with the PUT/CALL labels are the trade alerts.
- // Trade in specified direction 60sec (can also use 120sec without Martingale).
- //
- // * Notes *
- //
- // * Reference *
- // - This code use Bollinger calc by JayRogers in "[JR] Multi Bollinger Heat Bands - EMA/Break options"
- // - MA variant function from Scalp Jockey - MTF MA Cross Visual Strategizer by JayRogers
- // - Original idea from well know Broker's marketing youtube videos.
- //
- // === INPUTS ===
- // Bollinger Bands Inputs
- bb_length = input(6, minval=5, title="Bollinger Length")
- bb_mult = input(1.5, title="Bollinger Standard Deviation", minval=0.5, maxval=10)
- // RSI inputs
- rsiLength = input(9,minval=1,title="RSI Length")
- rsiUpper = input(75,minval=51,maxval=99,title="RSI Upper Level")
- rsiLower = input(25,minval=1,maxval=49,title="RSI Lower Level")
- // Stoch inputs
- StochLen = input(2, minval=1, title="Stochtastic Length")
- smoothK = input(3, minval=1,title="Stoch Smooth K Length")
- smoothD = input(3, minval=1,title="Stoch Smooth D Length")
- StochUpper = input(75, minval=51,maxval=100,title="Stoch Upper Level")
- StochLower = input(25,minval=1,maxval=49,title="Stoch Lower Level")
- // MA filter inputs
- dFilter = input(false,title="Use Directional Filter")
- // Fast MA - type, length
- fastTyp = input(defval="EMA", title="Fast MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- fastLen = input(defval=50, title="Fast - Length", minval=1)
- // Slow MA - type, length
- slowTyp = input(defval="EMA", title="Slow MA Type: SMA, EMA, WMA, VWMA, SMMA, DEMA, TEMA, HullMA, ZEMA, TMA, SSMA ( case sensitive )", type=string)
- slowLen = input(defval=200, title="Slow - Length", minval=1)
- //
- dCandles = input(3, minval=2, title="Candles to test Market Direction")
- resoln_ = input(0, minval=0, title="Candle body, how far past BB boundary in Points")
- // === /INPUTS ===
- // === FUNCTIONS ===
- // Returns MA input selection variant, default to SMA if blank or typo.
- variant(type, src, len) =>
- v1 = sma(src, len) // Simple
- v2 = ema(src, len) // Exponential
- v3 = wma(src, len) // Weighted
- v4 = vwma(src, len) // Volume Weighted
- v5 = na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len // Smoothed
- v6 = 2 * v2 - ema(v2, len) // Double Exponential
- v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
- v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
- v11 = sma(sma(src,len),len) // Triangular
- // SuperSmoother filter
- // © 2013 John F. Ehlers
- a1 = exp(-1.414*3.14159 / len)
- b1 = 2*a1*cos(1.414*3.14159 / len)
- c2 = b1
- c3 = (-a1)*a1
- c1 = 1 - c2 - c3
- v9 = c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
- // Zero Lag Exponential
- ema1 = ema(src, len)
- ema2 = ema(ema1, len)
- v10 = ema1+(ema1-ema2)
- // return variant, defaults to SMA if input invalid.
- 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
- // === /FUNCTIONS ===
- // === SERIES ===
- // Calculation for EMAs and market direction.
- SlowEMA = variant(slowTyp, close, slowLen)
- FastEMA = variant(slowTyp, close, fastLen)
- mDirection = rising(SlowEMA,dCandles) and FastEMA>SlowEMA ? +1 : falling(SlowEMA,dCandles) and FastEMA<SlowEMA ? -1 : 0
- // Get point value
- point = syminfo.mintick
- resoln = point * resoln_
- //
- // calculate current rsi value
- rsiVal = rsi(close, rsiLength)
- // Calculate Bollinger Bands Deviation
- bb_basis = sma(close, bb_length)
- dev = stdev(close, bb_length)
- bb_dev = bb_mult * dev
- // Upper band
- bb_high = bb_basis + bb_dev
- // Lower Band
- bb_low = bb_basis - bb_dev
- // get Stoch values
- StochK = sma(stoch(close, high, low, StochLen), smoothK)
- StochD = sma(StochK, smoothD)
- // === /SERIES ===
- // === PLOTTING ===
- // plot MAs
- plot(SlowEMA, title="SlowEMA", style=line, linewidth=2, color=red)
- plot(FastEMA, title="FastEMA", style=line, linewidth=2, color=olive)
- // --- Plot Bollinger Bands
- // plot basis
- plot(bb_basis, title="Basis Line", color=navy, transp=50)
- // plot and fill upper bands
- ubo = plot(bb_high, title="Upper Band Outer", color=blue, transp=20)
- lbo = plot(bb_low, title="Lower Band Outer", color=blue, transp=20)
- fill(ubo, lbo, title="Center Channel Fill", color=gray, transp=80)
- // Is RSI and Stoch OB or OS
- inRange = (rsiVal<rsiLower or rsiVal>rsiUpper) and (StochK<StochLower or StochK>StochUpper) and (StochD<StochLower or StochD>StochUpper)
- // Is this a breakout warning signal? this rebuilds until candle closed
- FastWarn_hi = ((close>open) and (not dFilter or (mDirection<0 and close<SlowEMA))) ? inRange and (close > bb_high+resoln) : false
- FastWarn_lo = ((close<open) and (not dFilter or (mDirection>0 and close>SlowEMA))) ? inRange and (close < bb_low-resoln) : false
- // Do we have a breakout signal?
- 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
- 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
- // Generate alert condition
- bbAlert = FastWarn_hi or FastWarn_lo
- alertcondition(bbAlert, title="BBRSI Alert", message="BBRSI Trade Alert")
- // plot breakouts and create alert condition
- plotshape(FastWarn_hi, title="BB High Warning", style=shape.diamond, location=location.abovebar, size=size.tiny, color=fuchsia, transp=0)
- plotshape(FastWarn_lo, title="BB Low Warning", style=shape.diamond, location=location.belowbar, size=size.tiny, color=fuchsia, transp=0)
- //
- plotshape(FastBreak_hi, title="BB High Alert", style=shape.triangledown, location=location.abovebar, text="PUT", size=size.small, color=red, transp=0)
- plotshape(FastBreak_lo, title="BB Low Alert", style=shape.triangleup, location=location.belowbar, text="CALL", size=size.small, color=green, transp=0)
- // draw background bar to highlight
- Highlight = (FastWarn_hi or FastWarn_lo) ? fuchsia : FastBreak_hi ? red : FastBreak_lo ? green : na
- bgcolor(Highlight, transp=75)
- // === /PLOTTING ===
- //
- //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement