xmd79

RSI Moving Average Crossovers

Dec 19th, 2022
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1.  
  2.  
  3. //@version=5
  4. indicator(title="RSI Moving Average Crossovers", shorttitle="RSIMAC", overlay=true,timeframe ="",timeframe_gaps =true )
  5.  
  6.  
  7. ma(source, length, type) =>
  8. type == "SMA" ? ta.sma(source, length) :
  9. type == "EMA" ? ta.ema(source, length) :
  10. type == "SMMA (RMA)" ? ta.rma(source, length) :
  11. type == "WMA" ? ta.wma(source, length) :
  12. type == "VWMA" ? ta.vwma(source, length) :
  13. na
  14.  
  15. // Options
  16. fastMA_len = input.int(20, "Fast Moving average Length", group="Moving averages")
  17. slowMA_len = input.int(50, "Slow Moving average Length", group="Moving averages")
  18. ma_type = input.string("EMA", title="MA Type", inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Moving averages")
  19. ma_source = input.source(close, "MA Source", group="Moving averages")
  20.  
  21. rsi_src = input.source(close, "RSI source", group="RSI")
  22. rsi_len = input.int(14, "RSI Length", group="RSI")
  23. rsi_ma_len = input.int(20, "Moving Average Length", group="RSI")
  24. rsi_ma_type = input.string("SMMA (RMA)", title="RSI MA Type", inline="MA #1", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI")
  25. ob_level = input.int(60, "Overbought level", group="RSI")
  26. os_level = input.int(40, "Oversold level", group="RSI")
  27.  
  28. show_rsi_crossovers = input.bool(false, "Plot RSI/MA crossovers", group="Options")
  29. show_ma_crossovers = input.bool(false, "Plot Trend MA crossovers", group="Options")
  30. show_screener = input.bool(false, "Show screener", group="Options")
  31.  
  32. // RSI
  33. rsi = ta.rsi(rsi_src, rsi_len)
  34. rsi_ma = ma(rsi, rsi_ma_len, rsi_ma_type)
  35.  
  36. // Moving Averages
  37. s = ma(ma_source, fastMA_len, ma_type)
  38. s2 = ma(ma_source, slowMA_len, ma_type)
  39.  
  40. // Colors
  41. uncertain_color=#bababa50
  42. bull_color=#48C9B0
  43. bear_color=#EC7063
  44. bg_bear_trend = #f50a0ae8
  45. bg_bear_correct = color.rgb(240, 81, 81 )
  46. bg_bull_trend = #00bc13c3
  47. bg_bull_correct = #2ca834
  48. up_shape_col=#069ecc
  49. down_shape_col=#aa0000
  50.  
  51. // Conditions
  52. bull = s > s2 and close > s2
  53. bear = s < s2 and close < s2
  54. col = (bull or bear) ? (rsi > rsi_ma ? bull_color : bear_color) : uncertain_color
  55.  
  56. // Plots
  57. rsilinecol = (bull or bear) ? (rsi > rsi_ma ? #0676cc : color.red): color.black
  58. malinecol = (bull or bear) ? (rsi < rsi_ma ? #0676cc : color.red): uncertain_color
  59. rsi_line = plot(rsi, color=rsilinecol, title="RSI")
  60. ma_line = plot(rsi_ma, color=malinecol, title="RSI MA")
  61.  
  62.  
  63.  
  64. // Table Data
  65. trend = bull ? "Bullish" : bear ? "Bearish": "Uncertain"
  66. rsi_cell_col = rsi > rsi_ma ? bull_color : bear_color
  67. rsi_ma_cell_color = rsi < rsi_ma ? bull_color : bear_color
  68. trend_cell_col = bull ? bull_color : bear ? bear_color : uncertain_color
  69. status = trend != "Uncertain" ? (bull and rsi < rsi_ma and rsi[1] < rsi_ma[1]) or (bear and rsi > rsi_ma and rsi[1] > rsi_ma[1]) ? "Correction" : "Impulse" : trend
  70. status_col = trend == "Uncertain" ? uncertain_color : (bull and rsi < rsi_ma) or (bear and rsi > rsi_ma) ? bear_color : bull_color
  71.  
  72. // Background Color
  73. bgcol = (trend == "Bullish" ? (status == "Impulse" ? bg_bull_trend : bg_bull_correct) : trend == "Bearish" ? (status == "Impulse" ? bg_bear_trend : bg_bear_correct) : na)
  74.  
  75. // Overbought & Oversold levels
  76. h = hline(ob_level, title="Overbought level", color=color.red)
  77. l = hline(os_level, title="Oversold level", color=#0676cc)
  78. m = hline(50, title="middle level", color=color.gray)
  79.  
  80. // Fill normal zone with trend color
  81. fill(h, l, color=bgcol, title="Trend background color")
  82.  
  83.  
  84.  
Advertisement
Add Comment
Please, Sign In to add comment