Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- study("BB ATR SR", shorttitle="BB ATR SR", overlay=true)
- custom_timeframe = input(title="Use another Timeframe?", type=bool, defval=false)
- highTimeFrame = input(title="Select The Timeframe", type=resolution, defval="60")
- res = custom_timeframe ? highTimeFrame : period
- //
- // ATR RS/RL
- //
- atr_src = close
- atr_length = input(14, minval=1)
- atr_mult = input(2.0, minval=0.001, maxval=50)
- atr_maLen =input(7,title="maLength")
- atr_highest = highest(3)
- atr_highest_src = security(tickerid, res, high, false)
- atr_lowest = highest(3)
- atr_lowest_src = security(tickerid, res, low, false)
- atr_sma = sma(atr_src, atr_length)
- atr_basis = security(tickerid, res, atr_sma, false)
- atr_atr = atr(atr_length)
- atr_dev = atr_mult * security(tickerid, res, atr_atr, false)
- atr_upper = atr_basis + atr_dev
- atr_lower = atr_basis - atr_dev
- atr_bbr = (atr_src - atr_lower) / (atr_upper - atr_lower)
- atr_bbe = ema(atr_bbr, atr_maLen)
- atr_up = atr_bbe[1]>atr_bbe and atr_bbe[2]<atr_bbe[1]?atr_bbe:na
- atr_bt = atr_bbe[1]<atr_bbe and atr_bbe[2]>atr_bbe[1]?atr_bbe:na
- atr_topH = na(atr_up)==0 ? atr_highest_src : na
- atr_bottomL = na(atr_bt)==0 ? atr_lowest_src : na
- atr_tf = fixnan(atr_topH)
- atr_bf = fixnan(atr_bottomL)
- plot(atr_tf,color=red,style=circles,linewidth=2,offset=-1)
- plot(atr_bf,color=green,style=circles,linewidth=2,offset=-1)
- //
- // ATR BB
- //
- OverBought = input(70, minval=0)
- OverSold = input(20, maxval=100)
- src = close
- Length = input(50)
- normalize(series) =>
- h = highest(series, Length)
- l = lowest(series, Length)
- res = (series - l) / (h - l)
- len = input(5, minval=1)
- ma2 = wma(src*volume, len) / wma(volume, len) // vwma
- // ma2 = wma(src, len) // no volumes
- result1 = normalize(ma2)
- z = 100 * result1 // *100 is it because of rsi ?
- // https://www.tradingview.com/wiki/Context_Switching,_The_‘security’_Function
- // use this to avoid repaints
- resCustom = input("120", title="Time frame", options=["03", "15", "30", "45", "60","120","180","240","360","720","1440"]) // custom tfs
- value = security(tickerid, resCustom, z[1], barmerge.gaps_off, barmerge.lookahead_on)
- length = input(title="Bollinger Length", type=integer, defval=20, minval=1)
- multiplier = input(title="Bollinger Deviation", type=float, defval=2, minval=1)
- overbought = input(title="Overbought", type=integer, defval=1, minval=1)
- oversold = input(title="Oversold", type=integer, defval=0, minval=1)
- // inputs
- per = input(24, type=integer, minval=15, maxval=60)
- //
- // donchian channel + fibo
- //
- hb = highest(high, per) // High Border
- lb = lowest(low, per) // Low Border
- dist = hb - lb // range of the channel
- med = (hb + lb) / 2 // median of the channel
- hf = hb - dist*0.236 // Highest Fib
- chf = hb - dist*0.382 // Center High Fib
- clf = hb - dist*0.618 // Center Low Fib
- lf = hb - dist*0.764 // Lowest Fib
- //
- // pullback levels
- //
- // entry markers
- tol = atr(per) * 0.2 // tolerance for placing triangles and prediction candles at borders
- //initialise mutatables
- hftrue = true
- lftrue = true
- cftrue = true
- evupin = crossover(close, hf) // market enters up trend
- evupout = crossunder(close, hf) // market leaves up trend
- hftrue := evupin ? true : evupout ? false : hftrue[1] // mutatable true if in up trend
- evdownin = crossunder(close, lf) // market enters down trend
- evdownout = crossover(close, lf) // market leaves down trend
- lftrue := evdownin ? true : evdownout ? false : lftrue[1] // mutatable true if in down trend
- cftrue := not hftrue and not lftrue ? true : false // mutatable true if instrument is ranging
- // identify last bar
- last = barstate.islast
- last := barstate.isrealtime and isintraday ? not barstate.isconfirmed :barstate.islast
- // barstate.islast works also when all bars are confirmed and are history. However in real time and intradaycharts bars never lose this state.
- // In that situation 'not barstate.isconfirmed' (like not ishistory) is the better alternative. if you use intraday charts after closing time of
- // the markets "barstate.isrealtime and isintraday" will be false and the script will use barstate.islast.
- // situation (plotting only)
- hbdtrue = last and hftrue // up trend
- lbdtrue = last and lftrue // down trend
- //
- // Plottings
- //
- // plot channel and fibzones
- phb = plot(hbdtrue ? na : hb, title="high border", color=yellow)
- plb = plot(lbdtrue ? na : lb, title="low border", color=yellow)
- // plot entry markers
- plotshape(evupout ? hb + tol : na, style=shape.cross, location=location.absolute, color=red, size=size.tiny)
- plotshape(evdownout ? lb - tol : na, style=shape.cross, location=location.absolute, color=aqua, size=size.tiny)
- //
- // slow and fast RSI
- //
- RSIlength = input(14, title="RSI Period Length")
- RSIvaluehigh = input(55, title="RSI High")
- RSIvaluelow = input(40, title="RSI Low")
- price = close
- vrsi = rsi(price, RSIlength)
- buy = vrsi < RSIvaluelow
- sell = vrsi > RSIvaluehigh
- RSIlength1 = input(5, title="RSI Period Length1")
- RSIvaluehigh1 = input(55, title="RSI High")
- RSIvaluelow1 = input(40, title="RSI Low")
- price1 = close
- vrsi1 = rsi(price1, RSIlength1)
- buy1 = vrsi1 < RSIvaluelow1
- sell1 = vrsi > RSIvaluehigh1 // not used
- //
- // Bollinger Bands
- //
- BBlength = input(20, minval=1,title="Bollinger Bands SMA Period Length")
- BBmult = input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")
- BBbasis = sma(price, BBlength)
- BBdev = BBmult * stdev(price, BBlength)
- BBupper = BBbasis + BBdev
- BBlower = BBbasis - BBdev
- source = close
- buyEntry = crossover(source, BBlower)
- sellEntry = crossunder(source, BBupper)
- up1 = value < OverSold and crossover(close, atr_bf) and evdownout ? lb-tol : na
- up = value < OverSold and buy and vrsi < vrsi1 and evdownout ? lb-tol : na
- down2 = value > OverBought and crossunder(close, atr_tf) and evupout ? hb+tol : na
- down = value > OverBought and sell and vrsi > vrsi1 and evupout ? hb+tol : na
- down1 = value > OverBought and vrsi > vrsi1 and evupout ? hb+tol : na
- // plotting bb
- plot(BBbasis, color=aqua,title="Bollinger Bands SMA Basis Line")
- p1 = plot(BBupper, color=silver,title="Bollinger Bands Upper Line")
- p2 = plot(BBlower, color=silver,title="Bollinger Bands Lower Line")
- fill(p1, p2) // channel
- //
- // plottings signals and alerts
- //
- plotshape(up, title="buy", style=shape.triangleup,location=location.belowbar, color=green, transp=0, size=size.small)
- plotshape(down, title="sell", style=shape.triangledown,location=location.abovebar, color=red, transp=0, size=size.small)
- plotshape(up1, title="buy1", style=shape.triangleup,location=location.belowbar, color=green, transp=0, size=size.tiny)
- plotshape(down1, title="down", style=shape.triangledown,location=location.abovebar, color=red, transp=0, size=size.tiny)
- plotshape(down2, title="down1", style=shape.triangledown,location=location.abovebar, color=orange, transp=0, size=size.tiny)
- //
- // signals alerts
- //
- alertcondition(up, title='buy', message='go long')
- alertcondition(up1, title='buy1', message='go long1')
- alertcondition(down, title='sell', message='go short')
- alertcondition(down1, title='down', message='go short1')
- alertcondition(down2, title='down1', message='go short2')
- alertcondition(up or up1 or down or down1 or down2, title='signal', message='go')
- alertcondition(up or up1, title='longs', message='go longs')
- alertcondition(down or down1 or down2, title='shorts', message='go shorts')
- alertcondition(up or up1 or down or down1 or down2 or evupout or evdownout, title='all', message='gogo')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement