Advertisement
BigHodler

RSI Time is Gold v2

Mar 8th, 2025
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | Cryptocurrency | 0 0
  1. //@version=5
  2. strategy("RSI Time is Gold", 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)
  3.  
  4. // Inputs
  5. rsi_length = input(14)
  6. rsi_oversold = input(23)
  7. fast_ma = input(23)
  8. slow_ma = input(123)
  9. ADX_trend_strength = 20
  10. RSI_force_sell = 80
  11. stop_loss_percent = input(1, title="Stop Loss (%)") // Ajout d'un stop loss
  12.  
  13. // Variables
  14. var float rsi = na
  15. var bool isLongEntered = false
  16. var bool bearish_cross = false
  17. var bool bullish_cross = false
  18.  
  19. // Calculate indicators
  20. rsi := ta.rsi(close, rsi_length)
  21. fast_sma = ta.sma(close, fast_ma)
  22. slow_sma = ta.sma(close, slow_ma)
  23. fast_ema = ta.ema(close, fast_ma)
  24. slow_ema = ta.ema(close, slow_ma)
  25. fast_ema_slope = fast_ema - fast_ema[1]
  26. linreg_value = ta.linreg(fast_ema, 14, 0)
  27. [diPlus, diMinus, adx] = ta.dmi(14, 14)
  28.  
  29. bullish_cross := ta.crossover(fast_sma, slow_sma) and adx > ADX_trend_strength
  30. bearish_cross := ta.crossunder(fast_sma, slow_sma) and adx < ADX_trend_strength
  31.  
  32. // Trading strategy
  33. if (strategy.equity > 0)
  34.     if rsi < rsi_oversold or (bullish_cross and fast_ema_slope > 0)
  35.         strategy.entry("long", strategy.long)
  36.         isLongEntered := true  // Marquer l'entrée en position longue
  37.  
  38.     if (isLongEntered and fast_ema_slope > 0) or bearish_cross
  39.         strategy.close("long")
  40.         isLongEntered := false // Marquer la sortie de position longue
  41.     else
  42.         strategy.cancel("long") // Annuler la sortie de position longue si l'EMA rapide ne croise pas l'EMA lente
  43.  
  44. // Ajout d'un stop loss
  45. strategy.exit("Stop Loss", "long", stop=close * (1 - stop_loss_percent/100))
  46.  
  47. // Tracer la pente de l'EMA rapide
  48. plot(fast_ema_slope, title="Fast EMA Slope", color=color.blue)
  49.  
  50. // Plotting
  51. plot(linreg_value, title="LinReg Value", color=color.yellow, linewidth=2)
  52. plot(fast_ema, title="EMA (fastema)", color=color.blue, linewidth=2)
  53. plot(slow_ema, title="EMA (slowema)", color=color.fuchsia, linewidth=2)
  54.  
  55. // Plotting cross shapes and background colors
  56. var int crossSeries = na
  57. crossSeries := bullish_cross ? 1 : bearish_cross ? -1 : nz(crossSeries[1])
  58.  
  59. bgcolor(crossSeries == 1 ? color.new(color.green, 90) : crossSeries == -1 ? color.new(color.red, 90) : na)
  60.  
  61. plotshape(bullish_cross, title="Croisement haussier", style=shape.triangleup, color=color.green, location=location.abovebar)
  62. plotshape(bearish_cross, title="Croisement baissier", style=shape.triangledown, color=color.red, location=location.belowbar)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement