xmd79

Relative Strength Index with Range Shift

Sep 30th, 2021
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © kevindcarr
  3.  
  4. //@version=4
  5. study(title="Relative Strength Index with Range Shift", shorttitle="RSI", overlay=false)
  6.  
  7. var table conditionTable = table.new(position=position.top_right, columns=1, rows=1)
  8.  
  9. range = input(title="Range Bias", type=input.string, options=["Bullish", "Strong Bullish", "Bearish", "Strong Bearish", "No Bias"], defval="Bullish")
  10. lookbackPeriod = input(title="Lookback Period", type=input.integer, defval=14)
  11. source = input(title="Source", type=input.source, defval=close)
  12.  
  13. rangeShift(range) =>
  14. if (range == "Bullish")
  15. [40, 60, 80]
  16. else if (range == "Strong Bullish")
  17. [60, 70, 80]
  18. else if (range == "Bearish")
  19. [30, 45, 60]
  20. else if (range == "Strong Bearish")
  21. [30, 40, 50]
  22. else
  23. [30, 50, 70]
  24.  
  25. condition(rsi, range) =>
  26. [lo, mid, hi] = rangeShift(range)
  27. if (rsi < lo)
  28. [ color.green, "Very Oversold" ]
  29. else if (rsi < mid)
  30. [ color.yellow, "Oversold" ]
  31. else if (rsi < hi)
  32. [ color.orange, "Overbought" ]
  33. else
  34. [ color.red, "Very Overbought" ]
  35.  
  36. rsi = rsi(source, lookbackPeriod)
  37. [col, txt] = condition(rsi, range)
  38. table.cell(conditionTable, 0, 0, text=txt, bgcolor=col)
  39. plot(series=rsi, title="Relative Strength Index", color=col)
  40.  
Advertisement
Add Comment
Please, Sign In to add comment