Advertisement
xmd79

RSI/MFI - MTF - Entry signals/Trend colored bars - JD

Jan 24th, 2023
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. //@version=5
  2. //This indicator is designed to show give early entry signals as well as to follow trend moves, according to different settings.
  3. //
  4. //The indicator shows a histogram of the RSI ro MFI in relation to an ema of the RSI or MFI.
  5. //The histogram is then smoothed to give early reversal/entry signals.
  6. //The actual RSI/MFI line with oversold/overbought indication can be displayed or omitted, as preferred.
  7. //in addition to the RSI/MFI line or as an alternative to it, the background colour can be set to change folowing the RSI/MFI signals.
  8. //The timeframe can be chosen. Higher timeframes (eg. 3h) tend to give less false signals.
  9. //
  10. //@version=5
  11. //added support for custom Multiple Time Frame selection.
  12. //added option for choice of RSI or MFI as base indicator.
  13. //added option for price bar coloring according to the indicator. (deselecting "borders" in the "style" tab is recommended)
  14. //price bar coloring can be adjusted for different strategies:
  15. //1. following the slope of the histogram (for faster entry/exit signals)
  16. //2. according to positive or negative histogram (for longer moves)
  17. //3. according to pos. or neg. RSI/MFI (for longer term trend holds)
  18. //4. uptrend: biased towards faster buy signals and slower sell signals to stay in the uptrend
  19. //5. downtrend: biased towards faster sell signals and slower buy signals to stay in the downtrend
  20. //
  21. //A longer timeframe (eg. 3x) is recommended for following trend moves.
  22. //try different strategies to see what works better for RSI or MFI.
  23. //
  24. //JD.
  25.  
  26. indicator(title='RSI/MFI - MTF - Entry signals/Trend colored bars - JD', shorttitle='RSI/MFI - MTF - Entry signals/Trend colored bars - JD')
  27. useCurrentRes = input(false, title='Use Current Chart Resolution?')
  28. resCustom = input.timeframe(title='Use Different Timeframe? Uncheck Box Above', defval='180')
  29. show_mfi = input.int(1, minval=1, maxval=2, title='base indicator: 1= RSI, 2= MFI')
  30. src = close
  31. len = input.int(14, minval=1, title='RSI/MFI Length')
  32. len2 = input.int(4, minval=1, title='Smoothing Length')
  33. th1 = input.int(70, minval=1, title='overbought')
  34. th2 = input.int(30, minval=1, title='oversold')
  35. show_rsi = input(true, title='show RSI or MFI line')
  36. show_bg = input(false, title='show RSI or MFI background color')
  37. color_bars = input(false, title='color pricebars')
  38. color_base = input.int(1, minval=1, maxval=5, title='color bars based on: 1= histogram slope, 2=+/- histogram, 3=+/- rsi/mfi-line, 4= uptrend (sell bias), 5= downtrend (buy bias)')
  39.  
  40. res = useCurrentRes ? timeframe.period : resCustom
  41.  
  42. //MFI calcutaion
  43. TypPrice = hlc3
  44. upper_s = math.sum(volume * (ta.change(TypPrice) <= 0 ? 0 : TypPrice), len)
  45. lower_s = math.sum(volume * (ta.change(TypPrice) >= 0 ? 0 : TypPrice), len)
  46. mf = 100.0 - 100.0 / (1.0 + upper_s / lower_s)
  47.  
  48. //RSI/MFI selection
  49. rsi_1 = ta.rsi(src, len)
  50. rsi_base = show_mfi == 1 ? rsi_1 : mf
  51.  
  52. //output MTF
  53. rsi = request.security(syminfo.tickerid, res, rsi_base)
  54. smooth_base = ta.ema(rsi_base, len)
  55. smooth = request.security(syminfo.tickerid, res, smooth_base)
  56. smooth2 = ta.ema(rsi - smooth, len2)
  57. smooth_up = smooth >= smooth[1] ? true : false
  58. smooth2_up = smooth2 >= smooth2[2] ? true : false
  59. histo = rsi - smooth
  60.  
  61. //color definition
  62. color_1 = color.new(color.green, 0)
  63. color_2 = color.new(color.green, 50)
  64. emacolor = histo >= 0 ? smooth2_up ? color_1 : color_2 : smooth2_up ? color.maroon : color.red
  65. smooth2color = smooth2 >= smooth2[2] ? color.green : color.red
  66. color_3 = color.new(color.red, 75)
  67. color_4 = color.new(color.maroon, 85)
  68. color_5 = color.new(color.lime, 85)
  69. color_6 = color.new(color.green, 90)
  70. bcol = rsi < 50 ? rsi < th2 ? color_3 : color_4 : rsi > 50 ? rsi > th1 ? color_5 : color_6 : na
  71. color_7 = color.new(color.maroon, 85)
  72. color_8 = color.new(color.maroon, 20)
  73. color_9 = color.new(color.lime, 85)
  74. color_10 = color.new(color.green, 90)
  75. color_11 = color.new(color.green, 30)
  76. rsicol = bcol == color.new(color.red, 75) ? color.red : bcol == color_7 ? color_8 : bcol == color_9 ? color.lime : bcol == color_10 ? color_11 : na
  77. plot(rsi - smooth, title='RSI - histo', style=plot.style_histogram, color=emacolor, linewidth=2, transp=0)
  78. plot(smooth2, title='RSI - ma', color=smooth2color, linewidth=3, transp=20)
  79. plot(show_rsi ? rsi - 50 : na, linewidth=2, color=rsicol, transp=0)
  80. bgcolor(title='RSI overbought/oversold', color=show_bg ? bcol : na, transp=90)
  81. barcolor_ref = color_base == 1 ? smooth2color : color_base == 2 ? histo >= 0 ? color.green : color.red : color_base == 3 ? rsi >= 50 ? color.green : color.red : color_base == 4 ? histo <= 0 ? smooth2color : color.green : color_base == 5 ? histo >= 0 ? smooth2color : color.red : na
  82. color_12 = color.new(color.lime, 30)
  83. color_13 = color.new(color.red, 20)
  84. barc = barcolor_ref == color.green ? color_12 : color_13
  85. barcolor(color_bars ? barc : na)
  86.  
  87.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement