OPEN-SOURCE SCRIPT

RSI Strategy

148
//version=6
indicator("Billy's RSI Strategy", shorttitle="RSI Strategy", overlay=true)

// Parameters
overbought = 70
oversold = 30
rsi_period = 14
min_duration = 4
max_duration = 100

// Calculate RSI
rsiValue = ta.rsi(close, rsi_period)

// Check if RSI is overbought or oversold for the specified duration
longOverbought = math.sum(rsiValue > overbought ? 1 : 0, max_duration) >= min_duration
longOversold = math.sum(rsiValue < oversold ? 1 : 0, max_duration) >= min_duration

// Generate signals
buySignal = ta.crossover(rsiValue, oversold) and longOversold
sellSignal = ta.crossunder(rsiValue, overbought) and longOverbought

// Calculate RSI divergence
priceDelta = close - close[1]
rsiDelta = rsiValue - rsiValue[1]
divergence = priceDelta * rsiDelta < 0

strongBuySignal = buySignal and divergence
strongSellSignal = sellSignal and divergence

// Plotting
plotshape(series=buySignal and not strongBuySignal, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(series=sellSignal and not strongSellSignal, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")

plotshape(series=strongBuySignal, title="Strong Buy Signal", location=location.belowbar, color=color.green, style=shape.triangleup, text="Strong Buy")
plotshape(series=strongSellSignal, title="Strong Sell Signal", location=location.abovebar, color=color.red, style=shape.triangledown, text="Strong Sell")

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.