xmd79

RSI - Dynamic Overbought/Oversold Range

Oct 2nd, 2021
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 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. // © HeWhoMustNotBeNamed
  3.  
  4. // __ __ __ __ __ __ __ __ __ __ __ _______ __ __ __
  5. // / | / | / | _ / |/ | / \ / | / | / \ / | / | / \ / \ / | / |
  6. // $$ | $$ | ______ $$ | / \ $$ |$$ |____ ______ $$ \ /$$ | __ __ _______ _$$ |_ $$ \ $$ | ______ _$$ |_ $$$$$$$ | ______ $$ \ $$ | ______ _____ ____ ______ ____$$ |
  7. // $$ |__$$ | / \ $$ |/$ \$$ |$$ \ / \ $$$ \ /$$$ |/ | / | / |/ $$ | $$$ \$$ | / \ / $$ | $$ |__$$ | / \ $$$ \$$ | / \ / \/ \ / \ / $$ |
  8. // $$ $$ |/$$$$$$ |$$ /$$$ $$ |$$$$$$$ |/$$$$$$ |$$$$ /$$$$ |$$ | $$ |/$$$$$$$/ $$$$$$/ $$$$ $$ |/$$$$$$ |$$$$$$/ $$ $$< /$$$$$$ |$$$$ $$ | $$$$$$ |$$$$$$ $$$$ |/$$$$$$ |/$$$$$$$ |
  9. // $$$$$$$$ |$$ $$ |$$ $$/$$ $$ |$$ | $$ |$$ | $$ |$$ $$ $$/$$ |$$ | $$ |$$ \ $$ | __ $$ $$ $$ |$$ | $$ | $$ | __ $$$$$$$ |$$ $$ |$$ $$ $$ | / $$ |$$ | $$ | $$ |$$ $$ |$$ | $$ |
  10. // $$ | $$ |$$$$$$$$/ $$$$/ $$$$ |$$ | $$ |$$ \__$$ |$$ |$$$/ $$ |$$ \__$$ | $$$$$$ | $$ |/ |$$ |$$$$ |$$ \__$$ | $$ |/ |$$ |__$$ |$$$$$$$$/ $$ |$$$$ |/$$$$$$$ |$$ | $$ | $$ |$$$$$$$$/ $$ \__$$ |
  11. // $$ | $$ |$$ |$$$/ $$$ |$$ | $$ |$$ $$/ $$ | $/ $$ |$$ $$/ / $$/ $$ $$/ $$ | $$$ |$$ $$/ $$ $$/ $$ $$/ $$ |$$ | $$$ |$$ $$ |$$ | $$ | $$ |$$ |$$ $$ |
  12. // $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$/ $$$$$$/ $$/ $$/ $$$$$$/ $$$$$$$/ $$$$/ $$/ $$/ $$$$$$/ $$$$/ $$$$$$$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$$$$$$/
  13. //
  14. //
  15. //
  16. //@version=4
  17. study("RSI - Dynamic Overbought/Oversold Range", shorttitle="RSI-DR")
  18. resolution = input("", type=input.resolution, title="Resolution", group="RSI")
  19. source = input(close, title="Source", group="RSI")
  20. length = input(14, title="Length", group="RSI")
  21. repaint = input(true, title="Repaint", group="RSI")
  22. method = input("swma", title="Detection Method", group = "Overbought/Oversold Range", options=["highlow", "sma", "ema", "rma", "hma", "wma", "vwma", "swma"])
  23. rangeLength = input(50, step=10, title="Length", group="Overbought/Oversold Range")
  24.  
  25. f_security(_sym, _res, _src, _rep) => security(_sym, _res, _src[not _rep and barstate.isrealtime ? 1 : 0])[_rep or barstate.isrealtime ? 0 : 1]
  26.  
  27. f_get_ma(source, method, rangeLength)=>
  28. method == "sma" ? sma(source,rangeLength) :
  29. method == "ema" ? ema(source,rangeLength) :
  30. method == "rma" ? rma(source,rangeLength) :
  31. method == "hma" ? hma(source,rangeLength) :
  32. method == "wma" ? wma(source,rangeLength) :
  33. method == "vwma" ? vwma(source,rangeLength) :
  34. method == "swma" ? swma(source) :
  35. method == "high"? highest(source, rangeLength) :
  36. method == "low" ? lowest(source, rangeLength) : na
  37.  
  38. f_rsi_high(source, length, method, rangeLength)=> f_get_ma(highest(rsi(source, length), rangeLength), method == "highlow" ? "low" : method, length)
  39.  
  40. f_rsi_low(source, length, method, rangeLength)=> f_get_ma(lowest(rsi(source, length), rangeLength), method == "highlow" ? "high" : method, length)
  41.  
  42. rsi = f_security(syminfo.tickerid, resolution, rsi(source, length), repaint)
  43. rsiHigh = f_security(syminfo.tickerid, resolution, f_rsi_high(source, length, method, rangeLength), repaint)
  44. rsiLow = f_security(syminfo.tickerid, resolution, f_rsi_low(source, length, method, rangeLength), repaint)
  45.  
  46. highSma = sma(highest(rsi, rangeLength), length)
  47. lowSma = sma(lowest(rsi, rangeLength), length)
  48. plot(rsi, title="RSI", color=color.blue)
  49. plot(rsiHigh, title="Overbought", color=color.red)
  50. plot(rsiLow, title="Oversold", color=color.green)
Advertisement
Add Comment
Please, Sign In to add comment