Indicator · Pine Script v6 · Own pane

Relative Strength

by theonetrade· code credited to bharatTrader

Calculates the relative strength performance of a security compared to a secondary comparative symbol over a specified lookback period.

View on GitHub

GitHub stars34on the repository
Pine versionv6current
Lines of code57
Settings15inputs
LicenceMIT
Last update2 weeks ago8 Nov 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

57 lines of Pine Script v6 from assets/indicator/bit-exact/relative_strength_of_a_stock_OhSlks3B.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

relative_strength_of_a_stock_OhSlks3B.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © bharatTrader

//@version=6
indicator('Relative Strength', shorttitle='Relative Strength')

//Input
source = input(title='Source', defval=close)
comparativeTickerId = input.symbol('NSE:NIFTY', title='Comparative Symbol')
length = input.int(123, minval=1, title='Period')
showZeroLine = input(defval=true, title='Show Zero Line')
showRefDateLbl = input(defval=true, title='Show Reference Label')
toggleRSColor = input(defval=true, title='Toggle RS color on crossovers')
showRSTrend = input.bool(defval=false, title='RS Trend,', group='RS Trend', inline='RS Trend')
base = input.int(title='Range', minval=1, defval=5, group='RS Trend', inline='RS Trend')
showMA = input.bool(defval=false, title='', group='RS Mean', inline='RS Mean')
lengthRSMA = input.int(50, minval=1, title='Period', group='RS Mean', inline='RS Mean')
showMAColor = input.bool(defval=true, title='Trend Color', group='RS Mean', inline='RS Mean')
showBubbles = input.bool(defval=true, title='', group='Price Confirmation', inline='Color')
lengthPriceSMA = input.int(50, minval=1, title='Period', group='Price Confirmation', inline='Color')
bullishColor = input.color(color.new(color.green, 85), title='+ve', group='Price Confirmation', inline='Color')
bearishColor = input.color(color.new(color.red, 85), title='-ve', group='Price Confirmation', inline='Color')

//Set up
baseSymbol = request.security(syminfo.tickerid, timeframe.period, source)
comparativeSymbol = request.security(comparativeTickerId, timeframe.period, source)

//Calculations
res = baseSymbol / baseSymbol[length] / (comparativeSymbol / comparativeSymbol[length]) - 1
resColor = toggleRSColor ? res > 0 ? color.green : color.red : color.blue
refDay = showRefDateLbl and barstate.islast ? dayofmonth(time[length]) : na
refMonth = showRefDateLbl and barstate.islast ? month(time[length]) : na
refYear = showRefDateLbl and barstate.islast ? year(time[length]) : na
refLabelStyle = res[length] > 0 ? label.style_label_up : label.style_label_down
refDateLabel = showRefDateLbl and barstate.islast ? label.new(bar_index - length, 0, text='RS-' + str.tostring(length) + ' reference, ' + str.tostring(refDay) + '-' + str.tostring(refMonth) + '-' + str.tostring(refYear), color=color.blue, style=refLabelStyle, yloc=yloc.price) : na
y0 = res - res[base]
angle0 = math.atan(y0 / base)  // radians
zeroLineColor = showRSTrend ? angle0 > 0.0 ? color.green : color.maroon : color.maroon
sma_res = ta.sma(res, lengthRSMA)
//Confirm symbol trend with a simple logic
sma_symb = ta.sma(baseSymbol, lengthPriceSMA)
pos_div = ta.rising(sma_symb, 3) and baseSymbol >= sma_symb
neg_div = ta.falling(sma_symb, 3) and baseSymbol < sma_symb
div_started = pos_div or neg_div
div_color = div_started ? pos_div ? bullishColor: neg_div ? bearishColor : na : na
ma_rising = ta.rising(sma_res, 3)
ma_falling = ta.falling(sma_res, 3)
ma_color = showMAColor and ma_rising ? color.green : showMAColor and ma_falling ? color.red : color.gray

//Plot
plot(showZeroLine ? 0 : na, linewidth=2, color=zeroLineColor, title='Zero Line / RS Trend')
plot(res, title='RS', linewidth=3, color=resColor)
plot(showMA ? sma_res : na, color=ma_color, title='MA', linewidth = 2)
plot(showBubbles and div_started ? res : na, "Confirmation Bubbles", div_color, 10, plot.style_circles)
//alertconditions
alertcondition(ma_rising, "Rising Strength", "Rising Strength")
alertcondition(ma_falling, "Declining Strength", "Declining Strength")

Overview

The indicator plots the relative strength curve in a separate pane alongside an optional zero line, reference point label, and moving average filter. It measures the RS trend angle and highlights price confirmation states using a price moving average to display visual status bubbles. Custom alerts can be configured for rising and falling relative strength movement.

Details

Published by

theonetrade on GitHub

Code credit

bharatTrader, as written in the script's header

Draws

Separate pane below the chart

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingbitcoinccxtcrypto-tradingllm-agentoffline-backtestingopen-source-tradingpine-scriptpine-to-pythonpinescriptpynecorepythonquantquantitative-financestrategy-backtestingtechnical-analysistrading-indicatorstrading-strategiestradingview

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourceclosesource
Comparative SymbolsymbolNSE:NIFTYcomparativeTickerId
Periodint123length
Show Zero LinebooltrueshowZeroLine
Show Reference LabelbooltrueshowRefDateLbl
Toggle RS color on crossoversbooltruetoggleRSColor
RS Trend,boolfalseshowRSTrend
Rangeint5base
showMAboolfalseshowMA
Periodint50lengthRSMA
Trend ColorbooltrueshowMAColor
showBubblesbooltrueshowBubbles
Show all 15 settings
SettingTypeDefaultVariable
Periodint50lengthPriceSMA
+vecolorcolor.new(color.green, 85)bullishColor
-vecolorcolor.new(color.red, 85)bearishColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Schaff Trend Cycle

by everget
947 stars

This indicator plots the Schaff Trend Cycle in a separate pane. It subtracts a slow exponential moving average from a fast one, applies a stochastic cycle twice, and smooths each result to form a 0–100 oscillator. Line color follows the slope, or the upper and

Indicator v4 Oscillators & momentumTrend
Updated 5 weeks ago · GPL-3.0 GitHub repository of Schaff Trend Cycle

Beep Boop

by magic8bot
408 stars

This indicator calculates a modified MACD oscillator and signal line alongside a trend EMA filter, plotting the output as a stylized column histogram in a separate pane. Instead of plotting true MACD distance, it quantifies positive and negative histogram mome

Indicator v4 Oscillators & momentumTrend
Updated 3 years ago · MIT GitHub repository of Beep Boop

[RS]Standardized Trend Map

by ricardosantos79
261 stars

Standardized Trend Map calculates series momentum relative to active price range across 40 distinct lookback periods ranging from 2 to 80 bars on an exponential moving average source. Each standardized calculation rounds to an integer values of -1, 0, or 1 to

Indicator v4 TrendOscillators & momentum
Updated 5 years ago · None stated GitHub repository of [RS]Standardized Trend Map
228 stars

Multi-Timeframe Analysis Suite calculates trend direction and momentum conditions across five user-selected timeframes using moving averages, RSI, and Stochastic oscillators. It evaluates moving average slope and oscillator levels to compute trend alignment, m

Indicator v6 Screeners & dashboardsTrend
Updated 4 months ago · None stated GitHub repository of Multi-Timeframe Analysis Suite

ADX Histogram

by harryguiacorn
220 stars

This indicator calculates and displays the Average Directional Index (ADX) as a column histogram in a separate pane. It evaluates market trend strength by calculating directional movement metrics based on specified smoothing and DI length inputs. When the ADX

Indicator v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ADX Histogram

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers