Advertisement
xmd79

Moving Average Cross and RSI

Feb 1st, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 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. // © Uniden202
  3.  
  4. //@version=5
  5. indicator('Moving Average Cross and RSI', overlay=false, precision=0)
  6.  
  7. //variable
  8. var indicatorshort = 0.0
  9. var indicatorlong = 0.0
  10.  
  11. // Define variables for MAC
  12. ema8 = ta.ema(close, 10)
  13. ema24 = ta.ema(close, 30)
  14.  
  15. // Plot EMAs
  16. plot(ema8, color=color.rgb(255, 82, 82, 100))
  17. plot(ema24, color=color.rgb(33, 150, 243, 100))
  18.  
  19.  
  20. // Define condition to long
  21. longcondition = ema8 > ema24
  22. if longcondition
  23. indicatorlong := 100
  24. indicatorlong
  25. else
  26. shortcondition = ema8 < ema24
  27. if shortcondition
  28. indicatorlong := na
  29. indicatorlong
  30. // Define Condition to Short
  31. Shortcondition = ema8 < ema24
  32. if Shortcondition
  33. indicatorshort := 0
  34. indicatorshort
  35. else
  36. shortcondition = ema8 > ema24
  37. if shortcondition
  38. indicatorshort := na
  39. indicatorshort
  40.  
  41. // Entry and Exit conditions for the trade
  42. long_entry = ema8 > ema24 and ema8[1] <= ema24[1]
  43. short_entry = ema8 < ema24 and ema8[1] >= ema24[1]
  44. closelong = ema8 < ema24 and not long_entry[2]
  45. closeshort = ema8 > ema24 and not short_entry[2]
  46.  
  47. // Plot the direction of the trade
  48. plot(indicatorshort, title='indicatorshort', color=color.rgb(78, 177, 81, 100))
  49. plot(indicatorlong, title='indicatorlong', color=color.rgb(78, 177, 81, 100))
  50. // Define variables for RSI
  51. rsi_length = 8
  52. rsi_source = hl2
  53. rsi_ema_length = 3
  54.  
  55. // Calculate RSI
  56. rsi = ta.rsi(rsi_source, rsi_length)
  57. upper = 64
  58. lower = 30
  59.  
  60. // Calculate EMA for RSI
  61. rsi_ema = ta.ema(rsi, rsi_ema_length)
  62.  
  63. // Plot RSI and EMA
  64. plot(rsi, style=plot.style_line, color=color.rgb(32, 146, 240), linewidth=2, title='RSI')
  65. plot(rsi_ema, style=plot.style_line, color=color.rgb(255, 82, 82), linewidth=2, title='EMA(RSI)')
  66. plot(upper, title='Overbought', color=color.rgb(218, 218, 218), linewidth=1, style=plot.style_circles)
  67. plot(lower, title='Overbought', color=color.rgb(218, 218, 218), linewidth=1, style=plot.style_circles)
  68. //plot(wtCross ? wt2 : na, title = 'Buy and sell circle', color = signalColor, style = plot.style_circles, linewidth = 3, transp = 15)
  69. plot(indicatorshort, 'Short', color=color.rgb(240, 77, 113), style=plot.style_circles, linewidth=3, offset=1)
  70. plot(indicatorlong, 'Long', color=color.rgb(36, 250, 17, 17), style=plot.style_circles, linewidth=3, offset=1)
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement