Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- 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)
- // Inputs
- rsi_length = input(14)
- rsi_oversold = input(23)
- fast_ma = input(23)
- slow_ma = input(123)
- ADX_trend_strength = 20
- RSI_force_sell = 80
- stop_loss_percent = input(1, title="Stop Loss (%)") // Ajout d'un stop loss
- // Variables
- var float rsi = na
- var bool isLongEntered = false
- var bool bearish_cross = false
- var bool bullish_cross = false
- // Calculate indicators
- rsi := ta.rsi(close, rsi_length)
- fast_sma = ta.sma(close, fast_ma)
- slow_sma = ta.sma(close, slow_ma)
- fast_ema = ta.ema(close, fast_ma)
- slow_ema = ta.ema(close, slow_ma)
- fast_ema_slope = fast_ema - fast_ema[1]
- linreg_value = ta.linreg(fast_ema, 14, 0)
- [diPlus, diMinus, adx] = ta.dmi(14, 14)
- bullish_cross := ta.crossover(fast_sma, slow_sma) and adx > ADX_trend_strength
- bearish_cross := ta.crossunder(fast_sma, slow_sma) and adx < ADX_trend_strength
- // Trading strategy
- if (strategy.equity > 0)
- if rsi < rsi_oversold or (bullish_cross and fast_ema_slope > 0)
- strategy.entry("long", strategy.long)
- isLongEntered := true // Marquer l'entrée en position longue
- if (isLongEntered and fast_ema_slope > 0) or bearish_cross
- strategy.close("long")
- isLongEntered := false // Marquer la sortie de position longue
- else
- strategy.cancel("long") // Annuler la sortie de position longue si l'EMA rapide ne croise pas l'EMA lente
- // Ajout d'un stop loss
- strategy.exit("Stop Loss", "long", stop=close * (1 - stop_loss_percent/100))
- // Tracer la pente de l'EMA rapide
- plot(fast_ema_slope, title="Fast EMA Slope", color=color.blue)
- // Plotting
- plot(linreg_value, title="LinReg Value", color=color.yellow, linewidth=2)
- plot(fast_ema, title="EMA (fastema)", color=color.blue, linewidth=2)
- plot(slow_ema, title="EMA (slowema)", color=color.fuchsia, linewidth=2)
- // Plotting cross shapes and background colors
- var int crossSeries = na
- crossSeries := bullish_cross ? 1 : bearish_cross ? -1 : nz(crossSeries[1])
- bgcolor(crossSeries == 1 ? color.new(color.green, 90) : crossSeries == -1 ? color.new(color.red, 90) : na)
- plotshape(bullish_cross, title="Croisement haussier", style=shape.triangleup, color=color.green, location=location.abovebar)
- 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