Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator(title="RSI With Candlesticks", shorttitle="RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
- ma(source, length, type) =>
- switch type
- "SMA" => ta.sma(source, length)
- "Bollinger Bands" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- "SMMA (RMA)" => ta.rma(source, length)
- "WMA" => ta.wma(source, length)
- "VWMA" => ta.vwma(source, length)
- rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
- rsiSourceInput = input.source(close, "Source", group="RSI Settings")
- maTypeInput = input.string("EMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")
- maLengthInput = input.int(10, title="MA Length", group="MA Settings")
- ma2LengthInput = input.int(200, title="MA 2 Length", group="MA Settings")
- bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")
- showRsiLine = input.bool(false, title="Show RSI Line", group="RSI Settings")
- showRsiMA = input.bool(false, title="Show RSI MA", group="RSI Settings")
- showRsiMA2 = input.bool(false, title="Show RSI MA 2", group="RSI Settings")
- showMA_Fill = input.bool(false, title="Show MA Fill", group="RSI Settings")
- showCandles = input.bool(true, title="Show Candles", group="RSI Settings")
- up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
- down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
- rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- rsiMA = ma(rsi, maLengthInput, maTypeInput)
- rsiMA2 = ma(rsi, ma2LengthInput, maTypeInput)
- isBB = maTypeInput == "Bollinger Bands"
- rsiPlot = plot(showRsiLine ? rsi : na, "RSI", color=color.black, linewidth = 2)
- ma1 = plot(showRsiMA ? rsiMA : na, "RSI-based MA", color=color.teal, linewidth = 1)
- ma2 = plot(showRsiMA2 ? rsiMA2 : na, "RSI-based MA", color= #fe0000, linewidth = 1)
- rsiUpperBand = hline(70.5, "RSI Upper Band", color=#787B86)
- midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50), linestyle = hline.style_solid)
- rsiLowerBand = hline(30.5, "RSI Lower Band", color=#787B86)
- // rsi_resistance_top = hline(55, "RSI Resistance Top Line" , color=#00bcd4)
- // rsi_resistance_bottom = hline(52, "RSI Resistance Bottom Line", color=#00bcd4)
- // rsi_support_top = hline(38, "RSI Support Top Line", color=#00bcd4)
- // rsi_support_bottom = hline(34, "RSI Support Top Line", color=#00bcd4)
- // fill(rsi_resistance_top, rsi_resistance_bottom, color=#00bcd4, title="RSI Resistance Fill")
- // fill(rsi_support_top , rsi_support_bottom , color=#00bcd4, title="RSI Support Fill" )
- fill(ma1, ma2, color= rsiMA > rsiMA2 and showMA_Fill ? color.new(color.teal, 60) : rsiMA < rsiMA2 and showMA_Fill ? color.new(color.red, 60) : na, title="MA Fill")
- fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
- bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
- bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
- fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")
- midLinePlot = plot(50, color = na, editable = false, display = display.none)
- fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100), title = "Overbought Gradient Fill")
- fill(rsiPlot, midLinePlot, 30, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill")
- ///===> Candlestick Oscillators
- // c= ma(close,osc_length, maTypeInput)
- // o= ma(open ,osc_length, maTypeInput)
- // h= ma(high ,osc_length, maTypeInput)
- // l= ma(low ,osc_length, maTypeInput)
- c1 = ta.rsi(close, rsiLengthInput)
- o1 = ta.rsi(open , rsiLengthInput)
- h1 = ta.rsi(high , rsiLengthInput)
- l1 = ta.rsi(low , rsiLengthInput)
- // c3= ma(close,osc2_length, maTypeInput)
- // o3= ma(open,osc2_length, maTypeInput)
- // h3= ma(high,osc2_length, maTypeInput)
- // l3= ma(low,osc2_length, maTypeInput)
- // c2 = ta.rsi(c3, osc2_length)
- // o2 = ta.rsi(o3, osc2_length)
- // h2 = ta.rsi(h3, osc2_length)
- // l2 = ta.rsi(l3, osc2_length)
- // plotcandle(o1,h1,l1,c1, color = o < c ? color.white : color.black, wickcolor=color.black, bordercolor = color.black)
- plotcandle(showCandles ? o1 : na, showCandles ? h1 : na, showCandles ? l1 : na, showCandles ? c1 : na, color = o1 < c1 ? color.blue : color.black, wickcolor= o1 < c1 ? color.blue : color.black, bordercolor = o1 < c1 ? color.blue : color.black)
- // // Divergence
- // lookbackRight = 5
- // lookbackLeft = 5
- // rangeUpper = 60
- // rangeLower = 5
- // bearColor = color.red
- // bullColor = color.green
- // textColor = color.white
- // noneColor = color.new(color.white, 100)
- // plFound = na(ta.pivotlow(rsi, lookbackLeft, lookbackRight)) ? false : true
- // phFound = na(ta.pivothigh(rsi, lookbackLeft, lookbackRight)) ? false : true
- // _inRange(cond) =>
- // bars = ta.barssince(cond == true)
- // rangeLower <= bars and bars <= rangeUpper
- // //------------------------------------------------------------------------------
- // // Regular Bullish
- // // rsi: Higher Low
- // rsiHL = rsi[lookbackRight] > ta.valuewhen(plFound, rsi[lookbackRight], 1) and _inRange(plFound[1])
- // // Price: Lower Low
- // priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
- // bullCondAlert = priceLL and rsiHL and plFound
- // bullCond = showDivergence and bullCondAlert
- // plot(
- // plFound ? rsi[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bullish",
- // linewidth=2,
- // color=(bullCond ? bullColor : noneColor)
- // )
- // plotshape(
- // bullCond ? rsi[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bullish Label",
- // text=" Bull ",
- // style=shape.labelup,
- // location=location.absolute,
- // color=bullColor,
- // textcolor=textColor
- // )
- // //------------------------------------------------------------------------------
- // // Regular Bearish
- // // rsi: Lower High
- // rsiLH = rsi[lookbackRight] < ta.valuewhen(phFound, rsi[lookbackRight], 1) and _inRange(phFound[1])
- // // Price: Higher High
- // priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
- // bearCondAlert = priceHH and rsiLH and phFound
- // bearCond = showDivergence and bearCondAlert
- // plot(
- // phFound ? rsi[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bearish",
- // linewidth=2,
- // color=(bearCond ? bearColor : noneColor)
- // )
- // plotshape(
- // bearCond ? rsi[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bearish Label",
- // text=" Bear ",
- // style=shape.labeldown,
- // location=location.absolute,
- // color=bearColor,
- // textcolor=textColor
- // )
- // alertcondition(bullCondAlert, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.")
- // alertcondition(bearCondAlert, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement