Advertisement
BigHodler

Passioned RSI indicator

Oct 27th, 2024
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ (WinAPI) 2.89 KB | Cryptocurrency | 0 0
  1. //@version=5
  2. indicator("Passionned RSI Indicator", overlay=false)
  3.  
  4. // Inputs
  5. RSIlong = input(36, title="RSI Long Threshold")
  6. RSIcloseLong = input(68, title="RSI Close Threshold")
  7. showDivergence = input(true, title="Show Divergence")
  8. rsiLength = input(14, title="RSI Length")
  9. lookbackRight = input(5, title="Lookback Right")
  10. lookbackLeft = input(5, title="Lookback Left")
  11. rangeUpper = input(60, title="Range Upper")
  12. rangeLower = input(5, title="Range Lower")
  13.  
  14. // RSI
  15. rsiValue = ta.rsi(close, rsiLength)
  16.  
  17. // Create a separate RSI indicator in the lower panel
  18. rsiPlot = plot(rsiValue, color=rsiValue > 50 ? color.green : color.red, title="RSI", linewidth=2, style=plot.style_line)
  19. hline(70, "Overbought", color=color.red)
  20. hline(30, "Oversold", color=color.green)
  21. plot(RSIlong, color=color.rgb(255, 255, 255))
  22. plot(RSIcloseLong, color=color.rgb(255, 255, 255))
  23.  
  24. // Fill the space between the overbought and oversold levels
  25. fill(hline(70), hline(30), color=color.new(color.gray, 90))
  26.  
  27. // Divergence
  28. bearColor = color.red
  29. bullColor = color.green
  30. textColor = color.white
  31. noneColor = color.new(color.white, 100)
  32.  
  33. plFound = na(ta.pivotlow(rsiValue, lookbackLeft, lookbackRight)) ? false : true
  34. phFound = na(ta.pivothigh(rsiValue, lookbackLeft, lookbackRight)) ? false : true
  35. _inRange(cond) =>
  36.     bars = ta.barssince(cond == true)
  37.     rangeLower <= bars and bars <= rangeUpper
  38.  
  39. // Regular Bullish
  40. // rsi: Higher Low
  41. rsiHL = rsiValue[lookbackRight] > ta.valuewhen(plFound, rsiValue[lookbackRight], 1) and _inRange(plFound[1])
  42.  
  43. // Price: Lower Low
  44. priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
  45. bullCondAlert = priceLL and rsiHL and plFound[1]
  46. bullCond = showDivergence and bullCondAlert
  47.  
  48. plot(
  49.      plFound ? rsiValue[lookbackRight] : na,
  50.      offset=-lookbackRight,
  51.      title="Regular Bullish",
  52.      linewidth=2,
  53.      color=(bullCond ? bullColor : noneColor)
  54.      )
  55.  
  56. plotshape(
  57.      bullCond ? rsiValue[lookbackRight] : na,
  58.      offset=-lookbackRight,
  59.      title="Regular Bullish Label",
  60.      text=" Bull ",
  61.      style=shape.labelup,
  62.      location=location.absolute,
  63.      color=bullColor,
  64.      textcolor=textColor
  65.      )
  66.  
  67. // Regular Bearish
  68. // rsi: Lower High
  69. rsiLH = rsiValue[lookbackRight] < ta.valuewhen(phFound, rsiValue[lookbackRight], 1) and _inRange(phFound[1])
  70.  
  71. // Price: Higher High
  72. priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
  73. bearCondAlert = priceHH and rsiLH and phFound[1]
  74. bearCond = showDivergence and bearCondAlert
  75.  
  76. plot(
  77.      phFound ? rsiValue[lookbackRight] : na,
  78.      offset=-lookbackRight,
  79.      title="Regular Bearish",
  80.      linewidth=2,
  81.      color=(bearCond ? bearColor : noneColor)
  82.      )
  83.  
  84. plotshape(
  85.      bearCond ? rsiValue[lookbackRight] : na,
  86.      offset=-lookbackRight,
  87.      title="Regular Bearish Label",
  88.      text=" Bear ",
  89.      style=shape.labeldown,
  90.      location=location.absolute,
  91.      color=bearColor,
  92.      textcolor=textColor
  93.      )
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement