xmd79

RSI Algo

Oct 15th, 2021
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. //@version=5
  2. //Orignial Author: https://www.tradingview.com/u/miyako.pro/
  3. //Revised: War-Jackel
  4.  
  5. indicator('RSI Algo', overlay=true)
  6.  
  7. //-- Colors
  8.  
  9. colorRed = #ff0000
  10. colorPurple = #e600e6
  11. colorGreen = #3fff00
  12. colorOrange = #e2a400
  13. colorBlack = #000000
  14. colorWhite = #FFFFFF
  15. colorYellow = #ffff00
  16. colorGold = #f57c00
  17. colorMidGreen = #069d11
  18. colorDeepRed = #800000
  19. colorMidRed = #c50808
  20. colorLavendar = #8d4dff
  21. colorDarkGreen = #016808
  22. colorTrans = color.new(colorBlack, 100)
  23. colorTransGreen = color.new(colorGreen, 80)
  24. colorTransRed = color.new(colorRed, 80)
  25.  
  26. //-- Inputs
  27.  
  28. myPeriod = input(defval=14, title='Period')
  29. myThresholdUp = input(defval=70, title='Upper Threshold')
  30. myThresholdDn = input(defval=30, title='Lower Threshold')
  31. myAlgoFlipToggle = input(defval=false, title='Imverse Algorthim')
  32. myLineToggle = input(defval=true, title='Show Lines')
  33. myLabelToggle = input(defval=true, title='Show Labels')
  34.  
  35. myRSI = ta.rsi(close, myPeriod)
  36.  
  37. //-- Variables
  38.  
  39. buy = myAlgoFlipToggle ? ta.falling(myRSI, 1) and ta.cross(myRSI, myThresholdDn) : ta.rising(myRSI, 1) and ta.cross(myRSI, myThresholdUp)
  40. sell = myAlgoFlipToggle ? ta.rising(myRSI, 1) and ta.cross(myRSI, myThresholdUp) : ta.falling(myRSI, 1) and ta.cross(myRSI, myThresholdDn)
  41.  
  42. var myPosition = 0
  43.  
  44. myPosition := buy == 1 ? 0 : sell == 1 or myPosition[1] == 1 ? 1 : 0
  45.  
  46. trendColor = buy ? colorTransRed : sell ? colorTransGreen : na
  47.  
  48. var isLong = false
  49. var isShort = false
  50.  
  51. buySignal = not isLong and myLabelToggle ? buy and myPosition[1] == 1 ? low - 0.005 : na : na // Buy only if we are not already long
  52. sellSignal = not isShort and myLabelToggle ? sell and myPosition[1] == 0 ? high + 0.005 : na : na // Sell only if we are not already short
  53.  
  54. if buySignal
  55. isLong := true
  56. isShort := false
  57. isShort
  58.  
  59. if sellSignal
  60. isLong := false
  61. isShort := true
  62. isShort
  63.  
  64. //-- Plots
  65.  
  66. plot(myLineToggle ? buy and myPosition[1] == 1 ? low - 0.004 : sell and myPosition[1] == 0 ? high + 0.004 : na : na, color=trendColor, linewidth=4, editable=false)
  67.  
  68. plotshape(series=buySignal, style=shape.labelup, location=location.belowbar, color=colorGreen, size=size.tiny, editable=true, text='Long', textcolor=color.new(color.black, 0), title='Long Label')
  69. plotshape(series=sellSignal, style=shape.labeldown, location=location.abovebar, color=colorRed, size=size.tiny, editable=true, text='Short', textcolor=color.new(color.white, 0), title='Short Label')
  70.  
  71. //-- Alerts
  72.  
  73. alertcondition(buySignal, title='Long', message='Long @ {{close}}')
  74. alertcondition(sellSignal, title='Short', message='Short @ {{close}}')
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment