OPEN-SOURCE SCRIPT
Relative Strength (RS) - Mansfield Style

Relative Strength (RS) measures how a symbol performs against a chosen
benchmark. Instead of plotting the raw price ratio — whose scale differs
from one symbol to another and makes comparison difficult — this script
normalizes the ratio (symbol close / benchmark close) against its own
simple moving average over a configurable lookback "Period". The result
is a zero-centered line that reads the same way on any symbol:
- RS above 0 and rising → the asset is outperforming the benchmark
- RS below 0 and falling → the asset is underperforming
- Zero-line crossings → shifts in relative leadership
Only the direction and the position relative to zero matter, not the
absolute value.
█ HOW IT WORKS
1. The script requests the benchmark's close on the selected timeframe.
2. It computes the raw ratio: symbol close / benchmark close.
3. The ratio is divided by its SMA over the "Period" lookback, minus 1 —
expressing how far the current relative strength stands above or
below its recent average.
4. An optional moving average of RS can be displayed as a signal line.
█ INPUTS
- Comparative Symbol: the benchmark (an index such as SPX, a sector
index, or any peer symbol — e.g. compare gold against silver).
- Period (default 50): normalization lookback. Shorter = more reactive,
longer = smoother and slower.
- Show Moving Average / Moving Average Period: optional smoothing line.
- Timeframe: leave empty to use the chart's timeframe, or select a
higher timeframe for multi-timeframe analysis.
█ HOW TO USE
Apply the indicator to any symbol. When RS holds above zero, the asset
is leading its benchmark — favor it for relative-strength strategies
(buy strength). When RS holds below zero, the asset is lagging — avoid
it or rotate out. Zero-line crossovers flag early changes in relative
leadership, and two built-in alerts fire on these crossings.
RS is a relative tool, not a timing tool: an asset can outperform a
falling benchmark while still declining in absolute terms. Combine it
with your own trend or entry criteria.
█ CREDITS
The normalization method follows the Mansfield Relative Strength
concept popularized by Stan Weinstein in "Secrets for Profiting in
Bull and Bear Markets".
█ NOTE ON HIGHER TIMEFRAMES
When a higher timeframe is selected in the Timeframe input, the value
of the current forming bar updates until that bar closes. Historical
values do not repaint.
benchmark. Instead of plotting the raw price ratio — whose scale differs
from one symbol to another and makes comparison difficult — this script
normalizes the ratio (symbol close / benchmark close) against its own
simple moving average over a configurable lookback "Period". The result
is a zero-centered line that reads the same way on any symbol:
- RS above 0 and rising → the asset is outperforming the benchmark
- RS below 0 and falling → the asset is underperforming
- Zero-line crossings → shifts in relative leadership
Only the direction and the position relative to zero matter, not the
absolute value.
█ HOW IT WORKS
1. The script requests the benchmark's close on the selected timeframe.
2. It computes the raw ratio: symbol close / benchmark close.
3. The ratio is divided by its SMA over the "Period" lookback, minus 1 —
expressing how far the current relative strength stands above or
below its recent average.
4. An optional moving average of RS can be displayed as a signal line.
█ INPUTS
- Comparative Symbol: the benchmark (an index such as SPX, a sector
index, or any peer symbol — e.g. compare gold against silver).
- Period (default 50): normalization lookback. Shorter = more reactive,
longer = smoother and slower.
- Show Moving Average / Moving Average Period: optional smoothing line.
- Timeframe: leave empty to use the chart's timeframe, or select a
higher timeframe for multi-timeframe analysis.
█ HOW TO USE
Apply the indicator to any symbol. When RS holds above zero, the asset
is leading its benchmark — favor it for relative-strength strategies
(buy strength). When RS holds below zero, the asset is lagging — avoid
it or rotate out. Zero-line crossovers flag early changes in relative
leadership, and two built-in alerts fire on these crossings.
RS is a relative tool, not a timing tool: an asset can outperform a
falling benchmark while still declining in absolute terms. Combine it
with your own trend or entry criteria.
█ CREDITS
The normalization method follows the Mansfield Relative Strength
concept popularized by Stan Weinstein in "Secrets for Profiting in
Bull and Bear Markets".
█ NOTE ON HIGHER TIMEFRAMES
When a higher timeframe is selected in the Timeframe input, the value
of the current forming bar updates until that bar closes. Historical
values do not repaint.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.