Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © DDMyke
- //@version=5
- indicator(title="Donchian RSI Bands", shorttitle="dR$Ib", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
- //Inputs
- src = input(ohlc4, "Source")
- rbdBC = input.bool(false, 'RSI Bollinger Band Barcolor', group='Barcolor')
- rcBC = input.bool(false, 'RSI Cloud Barcolor', group='Barcolor')
- dcBC = input.bool(false, 'Donchian Basis Barcolor', group='Barcolor')
- showFrsi = input.bool(true, 'RSI', group='RSI')
- len = input.int(7, minval=1, title="Length", group='RSI')
- rsiUc = input(color.new(#00bcd4,0), title='Bullish Color', inline='rsi', group='RSI')
- rsiNc = input(color.new(#0c3299,0), title='Neutral Color', inline='rsi', group='RSI')
- rsiDc = input(color.new(#d930ff,0), title='Bearish Color', inline='rsi', group='RSI')
- rsiWidth = input.int(1, 'Line Width', minval=1, maxval=4, group='RSI')
- showDrsi = input.bool(false, 'RSI (Default Length)', inline='rsi2', group='RSI')
- rsi2C = input(color.new(#ffffff,50), title='Color', inline='rsi2', group='RSI' )
- showCloud = input(false, 'RSI Cloud', group='RSI')
- upCloud = input(color.new(#00bcd4,85), title='Bullish Cloud', inline='cloud', group='RSI')
- downCloud = input(color.new(#d930ff,85), title='Bearish Cloud', inline='cloud', group='RSI')
- showBB = input.bool(true, 'Bollinger Bands', group='Double Bollinger Bands')
- length = input.int(35, 'Length', group='Double Bollinger Bands')
- mult2 = input.float(0.5, minval=0.5, step=0.25, maxval=5, title='Outer Band Deviation', group='Double Bollinger Bands')
- mult = input.float(0.25, minval=0.25, step=0.25, maxval=5, title='Inner Band Deviation', group='Double Bollinger Bands')
- offset = input.int(0, "Offset", minval = -500, maxval = 500, group='Double Bollinger Bands')
- bbandColor = input(color.new(#131722,20), title='Color', group='Double Bollinger Bands')
- showBBbasis = input.bool(true, 'Basis', group = 'Double Bollinger Bands')
- disp = input.float(0.1, 'Multiplier', minval=0.025, step=0.025, maxval=2, group='Double Bollinger Bands')
- showDC = input.bool(true,'Donchian Channel', group='Donchian Channel')
- DClength = input.int(70, 'Length', group='Donchian Channel')
- DCwidth = input.int(5, 'Band Width', minval=1, maxval=20, group='Donchian Channel')
- dcUb = input(color.new(#00bcd4,85), title='Upper Band', inline='dcb', group='Donchian Channel')
- dcDb = input(color.new(#d930ff,85), title='Lower Band', inline='dcb', group='Donchian Channel')
- showDCB = input.bool(false,'Donchian Channel Basis', group='Donchian Channel')
- dcUc = input(color.new(#4caf50,0), title='Bullish Color', inline='dc', group='Donchian Channel')
- dcDc = input(color.new(#e91e63,0), title='Bearish Color', inline='dc', group='Donchian Channel')
- //Calculations
- //RSI
- up = ta.rma(math.max(ta.change(src), 0), len)
- down = ta.rma(-math.min(ta.change(src), 0), len)
- rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- crsi = rsi
- //RSI (Default Length)
- up2 = ta.rma(math.max(ta.change(src), 0), 14)
- down2 = ta.rma(-math.min(ta.change(src), 0), 14)
- rsi2 = down2 == 0 ? 100 : up2 == 0 ? 0 : 100 - (100 / (1 + up2 / down2))
- crsi2 = rsi2
- //Double Bollinger Bands
- basis = ta.sma(rsi, length)
- dev = mult * ta.stdev(rsi, length)
- dev2 = mult2 * ta.stdev(rsi, length)
- upper = basis + dev
- upper2 = basis + dev2
- lower = basis - dev
- lower2 = basis - dev2
- //Basis Dispersion
- UpDisp = basis + (upper - lower) * disp
- DownDisp = basis - (upper - lower) * disp
- d1 = plot(showBBbasis and UpDisp ? UpDisp : na, color=color.new(#131722, 100), title='BB Basis Upper', linewidth=1, editable=false)
- d2 = plot(showBBbasis and DownDisp ? DownDisp : na, color=color.new(#131722, 100), title='BB Basis Lower', linewidth=1, editable=false)
- //Donchian Channel
- upperdc = ta.highest(rsi,DClength)
- lowerdc = ta.lowest(rsi,DClength)
- basisdc = math.avg(upperdc, lowerdc)
- //Plots
- rsiColor = rsi > upper2 ? rsiUc : rsi < lower2 ? rsiDc : rsiNc
- dcColor = rsi > basisdc ? dcUc : rsi < basisdc ? dcDc : na
- cloudFill = rsi > rsi2 ? upCloud : downCloud
- cloudColor = rsi > rsi2 ? rsiUc : rsiDc
- barcolor(rbdBC ? rsiColor : na, editable=false)
- barcolor(dcBC ? dcColor : na, editable=false)
- barcolor(rcBC ? cloudColor : na, editable=false)
- plot(showFrsi and rsi ? rsi : na, 'RSI', color=rsiColor, linewidth=rsiWidth, editable=false)
- c1 = plot(crsi, 'CRSI', color=color.new(#000000,100), editable=false)
- plot(showDrsi and rsi2 ? rsi2 : na, 'RSI (Default Length)', color=rsi2C, linewidth=1, editable=false)
- c2 = plot(crsi2, 'CRSI2', color=color.new(#000000,100), editable=false)
- p1 = plot(showBB and upper ? upper : na, 'Inner Upper Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
- p2 = plot(showBB and upper2 ? upper2 : na, 'Outer Upper Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
- p3 = plot(showBB and lower ? lower : na, 'Inner Lower Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
- p4 = plot(showBB and lower2 ? lower2 : na, 'Outer Lower Band', color=color.new(#2a2e39,100), offset=offset, editable=false)
- plot(showDC and upperdc ? upperdc : na, color=dcUb, title='Donchian Channel Upper Band', linewidth=DCwidth, editable=false)
- plot(showDC and lowerdc ? lowerdc : na, color=dcDb, title='Donchian Channel Lower Band', linewidth=DCwidth, editable=false)
- plot(showDCB and basisdc ? basisdc : na, 'Donchian Channel Basis', color=dcColor, linewidth=1, editable=false)
- fill(p1,p2, color=bbandColor, title='Upper Band Fill', editable=false)
- fill(p3,p4, color=bbandColor, title='Upper Band Fill', editable=false)
- fill(d1, d2, color=showBBbasis ? bbandColor : na, title='BB Basis Fill', editable=false)
- fill(c1, c2, color=showCloud ? cloudFill : na, title='RSI Cloud Fill', editable=false)
- hline(50, color=color.new(#ff8160,85), linewidth=1, linestyle=hline.style_dashed)
- //end of this part
- //@version=5
- //indicator(title='Multi Time RSI', overlay=false)
- avg1 = input(title='Slow Average :', defval=21)
- avg2 = input(title='Fast Average :', defval=11)
- rsi_avg_step = input(title='RSI Avg Step :', defval=1.0)
- //inp = input(close)
- //Plot RSI
- rsiCurrent = ta.rsi(src, 11)
- rsi_current_plot = plot(rsiCurrent, color=color.new(color.black, 0), linewidth=2, style=plot.style_line, title='Current RSI Time Frame')
- rsi_avg = ta.ema(ta.rsi(src, 11), avg1)
- rsi_avg_plot = plot(rsi_avg, color=color.new(color.red, 0), linewidth=2, style=plot.style_line, title='Current AVG RSI Time Frame')
- rsi_avg_1 = ta.ema(ta.rsi(src, 11), avg2)
- rp1 = plot(rsi_avg_1, color=color.new(color.blue, 50), linewidth=1, style=plot.style_line, title='Current AVG RSI Time Frame')
- fc1 = if rsi_avg_1 < rsi_avg
- color.new(color.red, 30)
- else
- color.new(color.green, 30)
- fill(rsi_avg_plot, rp1, color=fc1, transp=0)
- fill_color = if rsi_avg > rsiCurrent and rsi_avg[1] - rsi_avg[0] > rsi_avg_step
- color.new(color.red, 50)
- else if rsi_avg < rsiCurrent and rsi_avg[0] - rsi_avg[1] > rsi_avg_step
- color.new(color.green, 50)
- fill(rsi_current_plot, rsi_avg_plot, color=fill_color, editable=true, title='RSI BAND', transp=50)
- b1z = hline(70, color=color.new(color.green, 100), linestyle=hline.style_dotted, linewidth=1, title='Top Range')
- bz = hline(60, color=color.new(color.green, 100), linestyle=hline.style_dotted, linewidth=1, title='High Range')
- sz = hline(40, color=color.new(color.red, 100), linestyle=hline.style_dotted, linewidth=1, title='Low Range')
- s1z = hline(30, color=color.new(color.red, 100), linestyle=hline.style_dotted, linewidth=1, title='Bottom Range')
- mz = hline(50, color=color.black, linestyle=hline.style_dotted, linewidth=1, title='Mid Range')
- fill(b1z, bz, color=color.new(color.green, 80))
- fill(s1z, sz, color=color.new(color.red, 80))
- buy_zone = if rsi_avg[0] - rsi_avg[1] > 1
- true
- else
- false
- plotshape(buy_zone, style=shape.triangleup, location=location.bottom, color=color.new(color.green, 0), size=size.tiny, title='Bulish Symbol')
- sell_zone = if rsi_avg[2] - rsi_avg[1] > 1
- true
- else
- false
- plotshape(sell_zone, style=shape.triangledown, location=location.top, color=color.new(color.red, 0), size=size.tiny, title='Bearish Symbol')
- //end of this part
- //@version=5
- //indicator(title="Money Flow Index", shorttitle="MFI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
- lengths = input.int(title="Length", defval=14, minval=1, maxval=2000)
- //src = input(hlc3)
- mf = ta.mfi(src, lengths)
- overbought=hline(80, title="Overbought", color=#787B86)
- oversold=hline(20, title="Oversold", color=#787B86)
- fill(overbought, oversold, color=color.rgb(126, 87, 194, 90), title="Background")
- mid = plot(50, color=color.black)
- lens = 14
- upd = ta.rma(math.max(ta.change(close), 0), lens)
- downd = ta.rma(-math.min(ta.change(close), 0), lens)
- rsis = downd == 0 ? 100 : upd == 0 ? 0 : 100 - (100 / (1 + upd / downd))
- l1 = plot(mf, "MF", color=color.blue)
- l2 = plot(rsis, "RSI", color=color.lime)
- var c = color.black
- if (mf < 50 and rsis < 50)
- c := color.rgb(255, 0, 0, 80)
- else if (mf >= 50 and rsis >= 50)
- c := color.rgb(0, 255, 0, 80)
- else
- c := color.rgb(0, 0, 0, 0)
- fill(l1, mid, color = c)
- fill(l2, mid, color = c)
Advertisement
Add Comment
Please, Sign In to add comment