Indicator · Pine Script v4 · On the chart

Relative Strength Line by @iArpanK

by iArpanK· code credited to Arpan_K

This indicator calculates the relative strength of a chart symbol relative to a benchmark index and plots the resulting line directly over the price chart.

View on GitHub

GitHub stars6on the repository
Pine versionv4older, still runs
Lines of code76
Settings9inputs
LicenceNone statedfile: MPL-2.0
Last update5 years ago19 Sep 2021

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

76 lines of Pine Script v4 from RS Line by @iArpanK.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

RS Line by @iArpanK.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Arpan_K
// Relative Strength Line by @iArpanK
// v1.3

// Find me on twitter @iArpanK
// For indicators development projects in PineScript/Amibroker/Python contact me on twitter @iArpanK or drop a mail at k.arpan@outlook.com

//@version=4
study("Relative Strength Line by @iArpanK v1.3", shorttitle = "RS Line by @iArpanK v1.3", overlay = true)

// Calculating index price
index = input("NIFTY", type = input.symbol, title = "Base Symbol", group = "Basic")
index_price = security(index, timeframe.period, close)

// Input New High Period
highPeriod = input(250, type = input.integer, title = "New High Period", group = "Basic")

// RS Line width
line_width = input(3, type = input.integer, title = "RS Line Width", options = [1,2,3,4], group = "Basic")

// Input RS Line color
upColor = input(title = "RS Line Color     Growing", type = input.color, defval = color.blue, group = "Basic", inline = "RS Line Color")
downColor = input(title = "⠀Falling", type = input.color, defval = color.fuchsia, group = "Basic", inline = "RS Line Color")

// Input scaling factor
sc_factor = input(title = "Scaling Factor   ", type = input.float, defval = 7, group = "Advanced")

// Input moving average
plotMA = input(title = "Moving Average", type = input.bool, defval = false, group = "Advanced", inline = "MA")
typeMA = input(title = "", defval = "Simple", options = ["Simple", "Exponential", "Weighted"], group = "Advanced", inline = "MA")
periodMA = input(title = "", type = input.integer, defval = 10, group = "Advanced", inline = "MA")

// Calculating RS & plotting it
RS = close * sc_factor * 1000 / index_price
linecolor = RS > RS[1] ? upColor : downColor
plot(RS, title = "RS Line", color = linecolor, linewidth = line_width)

// Plotting moving average
plot(plotMA ? (typeMA == "Simple" ? sma(RS, periodMA) :  typeMA == "Exponential" ? ema(RS, periodMA) : wma(RS, periodMA)) : na, color = color.new(#9598a1, 0), title = "Moving Average", linewidth = 2)

// Label for RS name
label_color = color.new(#0000FF, 100)
RS_label = barstate.islast ? label.new(bar_index, RS, text = "RS Line", size = size.normal, color = label_color, textcolor = #0000FF, style = label.style_label_left, textalign = text.align_right, yloc = yloc.price, xloc = xloc.bar_index) : na

// Label for RS new high

highest_(values, length) =>
    h_val = values[0]
    h_indx = 0
    if length >= 1
        for i = 0 to length-1
            if ( not na(values[i]) and values[i] > h_val  )
                h_indx := i
                h_val := values[i]
    h_val

lowest_(values, length) =>
    l_val = values[0]
    l_indx = 0
    if length >= 1
        for i = 0 to length-1
            if ( not na(values[i]) and values[i] < l_val )
                l_indx := i
                l_val := values[i]
    l_val

data1 = RS > highest_(RS, highPeriod)[1]
data2 = high > highest_(high, highPeriod)[1]
data3 = RS < lowest_(RS, highPeriod)[1]

plotshape(data1 ? RS : na, title = "RS New High", style = shape.circle, location = location.absolute, color = #0000FF, size = size.tiny, transp = 20)
plotshape(data1 and not data2 ? RS : na, title = "RS New High before Price", style = shape.labeldown, location = location.absolute, text = "H", textcolor = #0000FF , color = #00FF11, size = size.auto)
plotshape(data3 ? RS : na, title = "RS New Low", style = shape.circle, location = location.absolute, color = #FF0000, size = size.tiny, transp = 20)

// Thank You

Overview

Relative Strength Line by @iArpanK highlights new relative strength highs, new lows, and instances where relative strength reaches a new high before the price does. Users can configure the benchmark symbol, the lookback period for new highs, line appearance, an optional moving average overlay, and a scaling factor. Because it overlays on the main price chart, manual scale adjustment is required to align values properly.

Details

Published by

iArpanK on GitHub

Code credit

Arpan_K, as written in the script's header

Type

Indicator, Pine Script v4

Draws

On the price chart

Category

Breakout, Moving averages, Trend

Markets

Stocks, Indices

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.

Settings

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

SettingTypeDefaultVariable
Base SymbolsymbolNIFTYindex
New High Periodint250highPeriod
RS Line Widthint3line_width
RS Line Color     Growingcolorcolor.blueupColor
⠀Fallingcolorcolor.fuchsiadownColor
Scaling Factor   float7sc_factor
Moving AverageboolfalseplotMA
typeMAstringSimpletypeMA
periodMAint10periodMA
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

RSC Trend Trading Study

by readysetcryptocodes
43 stars

This indicator plots Donchian Channels alongside fast and slow simple moving averages directly on the price chart. It generates bullish breakout signals when the high reaches the upper channel while the close is above the 50 SMA (and optionally the 200 SMA). B

Indicator v4 TrendBreakout
Updated 2 years ago · None stated GitHub repository of RSC Trend Trading Study

Candle Stage Analysis

by ChartsLector
41 stars

This indicator classifies market trends into structured stages based on moving average alignments, compression, and ATR distance from the 50-period SMA. It tracks multiple exponential moving averages against the 50 SMA to detect basing phases, breakouts, trend

Indicator v6 TrendMoving averages
Updated 2 days ago · None stated GitHub repository of Candle Stage Analysis
5 stars

Calculates short and long Exponential Moving Averages alongside pivot high and low levels to identify breakout signals. The indicator plots a 20 EMA and a 50 EMA on the main price chart. It evaluates trend direction based on EMA crossover alignment, checks for

Indicator v4 Moving averagesTrend
Updated 3 years ago · Apache-2.0 GitHub repository of 20 EMA + 50 EMA + Breakout
3 stars

CSW Breakout Signals plots breakout buy and sell labels on the price chart when price breaks support or resistance after a trend change. Each signal can show a numbered confirmation score built from a moving-average cross, momentum, opening-range alignment, re

Indicator v5 BreakoutTrend
Updated 5 months ago · None stated GitHub repository of CSW Breakout Signals

More indicators

Trade Your Charts With a Regulated Broker

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

Compare brokers