OPEN-SOURCE SCRIPT

RSI Strategy

138
//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")

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.