OPEN-SOURCE SCRIPT

RSI Deviation BY DINVESTORQ

Overview:
This indicator analyzes the Relative Strength Index (RSI) over 252 days, calculating its mean (average) and standard deviation. Based on this, it sets an upper and lower threshold to determine overbought and oversold conditions.
Additionally, it calculates the correlation between RSI and price using a moving average, helping traders understand if RSI is moving in sync with price trends.
Key Features:
✅ RSI Deviation Bands

Upper Limit = RSI Avg + (2 × SD × 2.5)
Lower Limit = RSI Avg - (2 × SD × 2.5)
✅ Trading Signals:

Sell Signal: RSI crosses above the upper limit
Buy Signal: RSI drops below the lower limit
✅ RSI-Price Correlation Moving Average

Uses 50-day correlation between RSI and price
Helps confirm trend strength
✅ Customizable Parameters

RSI Length (Default: 252 Days)
Correlation Period (Default: 50 Days)
✅ Chart Visuals:

Plots RSI (blue), Upper Band (red), Lower Band (green)
Plots RSI-Price Correlation (orange)
Buy/Sell signals appear on chart


TradingView Indicator: RSI Deviation & Correlation Indicator
Overview:
This indicator analyzes the Relative Strength Index (RSI) over 252 days, calculating its mean (average) and standard deviation. Based on this, it sets an upper and lower threshold to determine overbought and oversold conditions.
Additionally, it calculates the correlation between RSI and price using a moving average, helping traders understand if RSI is moving in sync with price trends.

Key Features:
✅ RSI Deviation Bands

Upper Limit = RSI Avg + (2 × SD × 2.5)
Lower Limit = RSI Avg - (2 × SD × 2.5)
✅ Trading Signals:

Sell Signal: RSI crosses above the upper limit
Buy Signal: RSI drops below the lower limit
✅ RSI-Price Correlation Moving Average

Uses 50-day correlation between RSI and price
Helps confirm trend strength
✅ Customizable Parameters

RSI Length (Default: 252 Days)
Correlation Period (Default: 50 Days)
✅ Chart Visuals:

Plots RSI (blue), Upper Band (red), Lower Band (green)
Plots RSI-Price Correlation (orange)
Buy/Sell signals appear on chart
Pine Script for TradingView:
pinescript
Copy
Edit
//version=5
indicator("RSI Deviation & Correlation Indicator", overlay=false)

// User Inputs
length = input.int(252, title="RSI Period")
corr_length = input.int(50, title="Correlation Period")

// RSI Calculation
rsi_value = ta.rsi(close, length)

// Calculate Mean and Standard Deviation of RSI
rsi_avg = ta.sma(rsi_value, length)
rsi_sd = ta.stdev(rsi_value, length) * 2.5

// Define Upper and Lower Limits
upper_limit = rsi_avg + (rsi_sd * 2)
lower_limit = rsi_avg - (rsi_sd * 2)

// Buy and Sell Signals
buy_signal = rsi_value < lower_limit
sell_signal = rsi_value > upper_limit

// Correlation Moving Average between RSI and Price
rsi_price_correlation = ta.correlation(rsi_value, close, corr_length)

// Plot RSI with Bands
plot(rsi_value, title="RSI", color=color.blue)
plot(upper_limit, title="Upper Limit", color=color.red, linewidth=2)
plot(lower_limit, title="Lower Limit", color=color.green, linewidth=2)
plot(rsi_avg, title="Average RSI", color=color.gray, linewidth=2)

// Display Buy/Sell Signals on Chart
plotshape(buy_signal, location=location.bottom, color=color.green, style=shape.labelup, title="BUY Signal", size=size.small)
plotshape(sell_signal, location=location.top, color=color.red, style=shape.labeldown, title="SELL Signal", size=size.small)

// Plot Correlation Moving Average
plot(rsi_price_correlation, title="RSI-Price Correlation", color=color.orange, linewidth=2)

// Alerts for Buy/Sell
alertcondition(buy_signal, title="BUY Alert", message="RSI is below the Lower Limit - BUY Signal")
alertcondition(sell_signal, title="SELL Alert", message="RSI is above the Upper Limit - SELL Signal")
How to Use in TradingView:
1️⃣ Open TradingView and go to the Pine Editor
2️⃣ Paste the above Pine Script
3️⃣ Click Add to Chart
4️⃣ Adjust RSI Length and Correlation Period if needed
5️⃣ Buy/Sell alerts will trigger when conditions match

Trading Strategy:
📉 Sell (Short Entry) when RSI crosses above the upper limit
📈 Buy (Long Entry) when RSI drops below the lower limit
📊 Confirm trends with RSI-Price Correlation:

+1 means RSI and price are moving together
-1 means RSI and price are diverging
Final Notes:
Works best on higher timeframes (Daily, Weekly)
Helps filter overbought/oversold false signals
Can be combined with other indicators (MACD, Bollinger Bands, etc.)

Pernyataan Penyangkalan