Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Passionned RSI Indicator", overlay=false)
- // Inputs
- RSIlong = input(36, title="RSI Long Threshold")
- RSIcloseLong = input(68, title="RSI Close Threshold")
- showDivergence = input(true, title="Show Divergence")
- rsiLength = input(14, title="RSI Length")
- lookbackRight = input(5, title="Lookback Right")
- lookbackLeft = input(5, title="Lookback Left")
- rangeUpper = input(60, title="Range Upper")
- rangeLower = input(5, title="Range Lower")
- // RSI
- rsiValue = ta.rsi(close, rsiLength)
- // Create a separate RSI indicator in the lower panel
- rsiPlot = plot(rsiValue, color=rsiValue > 50 ? color.green : color.red, title="RSI", linewidth=2, style=plot.style_line)
- hline(70, "Overbought", color=color.red)
- hline(30, "Oversold", color=color.green)
- plot(RSIlong, color=color.rgb(255, 255, 255))
- plot(RSIcloseLong, color=color.rgb(255, 255, 255))
- // Fill the space between the overbought and oversold levels
- fill(hline(70), hline(30), color=color.new(color.gray, 90))
- // Divergence
- bearColor = color.red
- bullColor = color.green
- textColor = color.white
- noneColor = color.new(color.white, 100)
- plFound = na(ta.pivotlow(rsiValue, lookbackLeft, lookbackRight)) ? false : true
- phFound = na(ta.pivothigh(rsiValue, lookbackLeft, lookbackRight)) ? false : true
- _inRange(cond) =>
- bars = ta.barssince(cond == true)
- rangeLower <= bars and bars <= rangeUpper
- // Regular Bullish
- // rsi: Higher Low
- rsiHL = rsiValue[lookbackRight] > ta.valuewhen(plFound, rsiValue[lookbackRight], 1) and _inRange(plFound[1])
- // Price: Lower Low
- priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
- bullCondAlert = priceLL and rsiHL and plFound[1]
- bullCond = showDivergence and bullCondAlert
- plot(
- plFound ? rsiValue[lookbackRight] : na,
- offset=-lookbackRight,
- title="Regular Bullish",
- linewidth=2,
- color=(bullCond ? bullColor : noneColor)
- )
- plotshape(
- bullCond ? rsiValue[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 = rsiValue[lookbackRight] < ta.valuewhen(phFound, rsiValue[lookbackRight], 1) and _inRange(phFound[1])
- // Price: Higher High
- priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
- bearCondAlert = priceHH and rsiLH and phFound[1]
- bearCond = showDivergence and bearCondAlert
- plot(
- phFound ? rsiValue[lookbackRight] : na,
- offset=-lookbackRight,
- title="Regular Bearish",
- linewidth=2,
- color=(bearCond ? bearColor : noneColor)
- )
- plotshape(
- bearCond ? rsiValue[lookbackRight] : na,
- offset=-lookbackRight,
- title="Regular Bearish Label",
- text=" Bear ",
- style=shape.labeldown,
- location=location.absolute,
- color=bearColor,
- textcolor=textColor
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement