OPEN-SOURCE SCRIPT
Güncellendi AJ - RSI

# AJ - RSI — Multi-Timeframe RSI with Configurable Higher-TF Lock
## Overview
**AJ - RSI** is a clean, publish-ready Relative Strength Index that lets you **lock the RSI calculation to any timeframe you choose**, regardless of the timeframe your chart is on. By default it displays the **Monthly RSI (14)** on every chart — 1 minute, 1 hour, daily, weekly, monthly — so you always keep the higher-timeframe trend context in front of you while trading a lower timeframe.
## What makes it different
- **Timeframe-locked RSI:** Trade on a 15-minute chart while watching the true Monthly RSI. No need to flip charts.
- **Matches the built-in RSI exactly** on the requested timeframe (same length, same source, same math) — verified against TradingView's native RSI.
- **Non-repainting historical data.** Uses `request.security` with `barmerge.lookahead_off`, so no future-leak on closed bars.
- **Configurable RSI-based MA** (SMA / EMA / WMA / RMA) with adjustable length.
- **Three clear reference bands** — Overbought (80, red dotted), Midline (50, green solid), Oversold (30, green dotted) — with a subtle shaded zone for readability.
## How to use
- **Trend filter:** Monthly RSI > 50 = long-term uptrend bias; < 50 = downtrend bias. Trade lower-TF setups only in the direction of the higher-TF regime.
- **Momentum shifts:** A monthly RSI crossover above 50 often marks a durable trend change; crossunder below 50 signals loss of long-term momentum.
- **Overbought / Oversold:** Readings above 80 or below 30 on the higher timeframe highlight stretched conditions worthy of caution or mean-reversion attention.
- **RSI vs. its MA:** Use crossovers of the RSI and its moving average as an early momentum confirmation.
- **Weekly / Daily setups:** Change the Timeframe input to Weekly, Daily, or any other TF to reuse the same framework at different horizons.
## Inputs
**RSI**
- RSI Length (default 14)
- Source (default close)
- Timeframe — Chart, 1 min, 5 min, 1 Hour, 1 Day, 1 Week, 1 Month, Quarter (default 1 Month). Select "Chart" to follow the current chart timeframe.
**RSI Moving Average**
- MA Length (default 14)
- MA Type — SMA / EMA / WMA / RMA (default SMA)
**Levels**
- Upper Band (default 80, red dotted)
- Mid Band (default 50, green solid)
- Lower Band (default 30, green dotted)
## Built-in alerts
- RSI crosses above 50
- RSI crosses below 50
- RSI crosses above the Upper Band
- RSI crosses below the Lower Band
## Notes on behavior
- On the current (still-forming) higher-timeframe bar, the RSI updates in real time — the same way the built-in RSI would if you switched the chart to that timeframe. Historical bars are stable.
- The Line style / color / thickness of every plot and band can be adjusted from the indicator's **Style** tab.
## Disclaimer
This script is provided for educational and informational purposes only. It is not financial advice and does not constitute a recommendation to buy or sell any security. Past performance of any indicator does not guarantee future results. Always do your own research and manage your risk.
**Author:** Ayyanar Jayabalan
## Overview
**AJ - RSI** is a clean, publish-ready Relative Strength Index that lets you **lock the RSI calculation to any timeframe you choose**, regardless of the timeframe your chart is on. By default it displays the **Monthly RSI (14)** on every chart — 1 minute, 1 hour, daily, weekly, monthly — so you always keep the higher-timeframe trend context in front of you while trading a lower timeframe.
## What makes it different
- **Timeframe-locked RSI:** Trade on a 15-minute chart while watching the true Monthly RSI. No need to flip charts.
- **Matches the built-in RSI exactly** on the requested timeframe (same length, same source, same math) — verified against TradingView's native RSI.
- **Non-repainting historical data.** Uses `request.security` with `barmerge.lookahead_off`, so no future-leak on closed bars.
- **Configurable RSI-based MA** (SMA / EMA / WMA / RMA) with adjustable length.
- **Three clear reference bands** — Overbought (80, red dotted), Midline (50, green solid), Oversold (30, green dotted) — with a subtle shaded zone for readability.
## How to use
- **Trend filter:** Monthly RSI > 50 = long-term uptrend bias; < 50 = downtrend bias. Trade lower-TF setups only in the direction of the higher-TF regime.
- **Momentum shifts:** A monthly RSI crossover above 50 often marks a durable trend change; crossunder below 50 signals loss of long-term momentum.
- **Overbought / Oversold:** Readings above 80 or below 30 on the higher timeframe highlight stretched conditions worthy of caution or mean-reversion attention.
- **RSI vs. its MA:** Use crossovers of the RSI and its moving average as an early momentum confirmation.
- **Weekly / Daily setups:** Change the Timeframe input to Weekly, Daily, or any other TF to reuse the same framework at different horizons.
## Inputs
**RSI**
- RSI Length (default 14)
- Source (default close)
- Timeframe — Chart, 1 min, 5 min, 1 Hour, 1 Day, 1 Week, 1 Month, Quarter (default 1 Month). Select "Chart" to follow the current chart timeframe.
**RSI Moving Average**
- MA Length (default 14)
- MA Type — SMA / EMA / WMA / RMA (default SMA)
**Levels**
- Upper Band (default 80, red dotted)
- Mid Band (default 50, green solid)
- Lower Band (default 30, green dotted)
## Built-in alerts
- RSI crosses above 50
- RSI crosses below 50
- RSI crosses above the Upper Band
- RSI crosses below the Lower Band
## Notes on behavior
- On the current (still-forming) higher-timeframe bar, the RSI updates in real time — the same way the built-in RSI would if you switched the chart to that timeframe. Historical bars are stable.
- The Line style / color / thickness of every plot and band can be adjusted from the indicator's **Style** tab.
## Disclaimer
This script is provided for educational and informational purposes only. It is not financial advice and does not constitute a recommendation to buy or sell any security. Past performance of any indicator does not guarantee future results. Always do your own research and manage your risk.
**Author:** Ayyanar Jayabalan
Sürüm Notları
## New features
### 1. Mansfield Relative Strength (vs Index) — *off by default*
A new module that measures how a stock is performing relative to a benchmark.
- Formula: `RS% = ((Stock / Index) / SMA(ratio, len) - 1) * 100`
- Positive = outperforming the benchmark; negative = underperforming
- Configurable benchmark (default `NSE:CNX500`) and smoothing length (default 50)
- Rendered as a **thin solid line**, green when above 0 and red when below 0
- Optional **dotted zero line** (also hidden by default)
- Enable from the *Relative Strength (vs Index)* input group
### 2. RS Cross Markers on the RSI line — *on by default*
The signal-you-actually-trade layer.
- **Small filled green circle** on the RSI line when RS crosses above 0 (outperformance start)
- **Small filled red circle** on the RSI line when RS crosses below 0 (underperformance start)
- Cross detection runs **independently of the RS line toggle**, so you get the signal even while the RS line itself stays hidden
- Show/hide toggle plus separate color pickers in the new *RS Cross Markers* input group
### 3. Two new alertconditions
- Relative Strength crosses above 0 (outperforming benchmark)
- Relative Strength crosses below 0 (underperforming benchmark)
## Default / styling changes
- **RSI MA:** switched from **circles** to a **thin solid line at 50% opacity** (was full-opacity dotted circles). Line style can be changed to Dashed from the Style tab.
- **Band Fill (30–80):** now **unchecked by default** — enable it from the Style tab if you want the shaded band back.
- **RS zero line:** hidden by default (was visible in the earlier RS preview).
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.