xmd79

Quick-Glance RSI

Oct 1st, 2021
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. // @version=4
  2. // This source code is subject to the terms of the Mozilla Public License 2.0 https://mozilla.org/MPL/2.0/
  3. // ©mvs1231 || xxattaxx
  4. study("Quick-Glance RSI", shorttitle="QuickRSI",overlay=true)
  5. //Inputs
  6. RSI_Len = input(14, "RSI Length(14)", maxval=150)
  7. OB = input(70.0, "Overought Level(70)", minval=0, maxval=100)
  8. OS = input(30.0, "Oversold Levels(70)", minval=0, maxval=100)
  9. Offset = input(10, "Scale Offset(10)")
  10. eScale = input(true, "Show Scale 0-100?")
  11. eLine = input(true, "Show RSI Line?")
  12. eBox = input(true, "Show OB/OS box?")
  13. eLive = input(true, "Realtime?")
  14. //Workaround: function to prevent dropping last two zeros
  15. fstring(x) =>
  16. curr = str.format("{0,number,currency}", x)
  17. number = str.split(curr,"$")
  18. fstring = array.get(number,0)
  19. RSI = rsi(close, RSI_Len)
  20. //Scale for RSI Length
  21. HH = highest(high,RSI_Len)
  22. LL = lowest(low,RSI_Len)
  23. Range = HH - LL
  24. //Calculate RSI on overlay
  25. chartRSI = LL + (RSI / 100) * Range
  26. chartOS = LL + OS/100 * Range
  27. chartOB = LL + OB/100 * Range
  28. //Set colors
  29. obtext = color.new(color.lime,5)
  30. ostext = color.new(color.red,5)
  31. nntext = color.new(color.white,5)
  32. obbgr = color.new(color.maroon,80)
  33. osbgr = color.new(color.green,80)
  34. nnbgr = color.new(color.white,95)
  35. Plagueis = "Damask"
  36. rsicolor = RSI >= OB? obtext : RSI <= OS ? ostext : nntext
  37. darkcolor = RSI >= OB? obbgr : RSI <= OS ? osbgr : nnbgr
  38. //Draw lines/boxes
  39. line rsiLine = na
  40. label rsiLabel = na
  41. box obBox = na
  42. box osBox = na
  43. //scale labels
  44. label label100 = na
  45. label labelOB = na
  46. label label50 = na
  47. label labelOS = na
  48. label label0 = na
  49. //Enable Realtime or Delayed Calculations
  50. DrawNow = (eLive and barstate.isrealtime) or (not eLive and barstate.isconfirmed)
  51. //convert RSI to string and keep zeros after decimal
  52. fRSI = fstring(RSI)
  53. if DrawNow
  54. //Draw RSI Label
  55. rsitext = fRSI // + " (RSI " + tostring(RSI_Len) + ")"
  56. rsiLabel := label.new(bar_index + 2,chartRSI,text=rsitext,style=label.style_label_left,textcolor=rsicolor,color=darkcolor)
  57. // Draw RSI line
  58. if eLine
  59. rsiLine := line.new(bar_index-RSI_Len, chartRSI, bar_index + 2 , chartRSI, color=color.new(color.blue,20), extend=extend.none,
  60. style=line.style_solid, width=3)
  61. //Draw OB/OS box
  62. if eBox
  63. obBox := box.new(bar_index-RSI_Len,HH,bar_index + Offset,chartOB,bgcolor=obbgr,border_color=na)
  64. osBox := box.new(bar_index-RSI_Len,LL,bar_index + Offset,chartOS,bgcolor=osbgr,border_color=na)
  65. //Show 0-100 scale
  66. if eScale
  67. label100 := label.new(bar_index + Offset , HH, text="100",style=label.style_label_left,textcolor=nntext,color=na, size=size.tiny)
  68. labelOB := label.new(bar_index + Offset , chartOB, text=tostring(OB),style=label.style_label_left,textcolor=nntext,color=na, size=size.tiny)
  69. label50 := label.new(bar_index + Offset , LL + Range/2, text="50",style=label.style_label_left,textcolor=nntext,color=na, size=size.tiny)
  70. labelOS := label.new(bar_index + Offset , chartOS, text=tostring(OS),style=label.style_label_left,textcolor=nntext,color=na, size=size.tiny)
  71. label0 := label.new(bar_index + Offset , LL, text="0",style=label.style_label_left,textcolor=nntext,color=na, size=size.tiny)
  72. //Delete previous lines/boxes
  73. line.delete(rsiLine[1]), label.delete(rsiLabel[1]), label.delete(label100[1]), label.delete(labelOB[1])
  74. label.delete(label50[1]), label.delete(labelOS[1]), label.delete(label0[1])
  75. box.delete(obBox[1]), box.delete(osBox[1])
Advertisement
Add Comment
Please, Sign In to add comment