Advertisement
BigHodler

RSI Golden Cross Strategy

Feb 19th, 2025
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | Source Code | 0 0
  1. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © dravitch
  3. //@version=4
  4.  
  5. strategy("RSI Golden Cross Strategy", overlay=true, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0.02, initial_capital=1000, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
  6.  
  7. // Inputs
  8. rsi_length = input(14)
  9. rsi_oversold = input(20)
  10. rsi_overbought = input(90)
  11.  
  12. fast_ma = input(50)
  13. slow_ma = input(200)
  14.  
  15. // Variables
  16. var float rsi = na
  17. var bool bullish_cross = false
  18. var bool bearish_cross = false
  19.  
  20. // Calculate indicators
  21. rsi := rsi(close, rsi_length)
  22. fast_sma = sma(close, fast_ma)
  23. slow_sma = sma(close, slow_ma)
  24.  
  25. bullish_cross := crossover(fast_sma, slow_sma)
  26. bearish_cross := crossunder(fast_sma, slow_sma)
  27.  
  28. // Trading strategy
  29. if (strategy.equity > 0)
  30. if (rsi < rsi_oversold) or bullish_cross
  31. strategy.entry("long", strategy.long)
  32.  
  33. if bearish_cross
  34. strategy.close("long")
  35.  
  36.  
  37. if bearish_cross or rsi > rsi_overbought
  38. strategy.close("long")
  39.  
  40.  
  41. // Plots
  42. //plot(rsi, color=color.blue, title="RSI", linewidth=2)
  43. p1 = plot(fast_sma, color=color.purple, title="Fast SMA", linewidth=2)
  44. p2 = plot(slow_sma, color=color.blue, title="Slow SMA", linewidth=2)
  45.  
  46. fill(p1, p2, (rsi < rsi_oversold and bullish_cross) or bearish_cross ? na : color.new(color.green, 70))
  47.  
  48.  
Tags: RSI EMA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement