Library · Pine Script v5 · Library

RSI Lib

by augustoerni

This library exports a function that calculates the Relative Strength Index from the close price.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code18
Settings0inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago9 Aug 2024

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 library, select all of the template text and paste. Press Save and give it a name.
  4. 4Publish or import itA library draws nothing. Publish it from the editor, then import its functions in your own scripts.

Source Code

18 lines of Pine Script v5 from libraries/rsi_lib.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

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

//@version=5

library("rsi_lib", overlay=true)

rsiFunction(rsiLengthPeriod) =>
    lengthPeriod = rsiLengthPeriod
    source = close
    differenceSource = ta.change(source)
    gain = na(differenceSource) ? na : math.max(differenceSource, 0)
    loss = na(differenceSource) ? na : -math.min(differenceSource, 0)
    averageGain = ta.rma(gain, lengthPeriod)
    averageLoss = ta.rma(loss, lengthPeriod)
    relativeStrength = (averageGain / averageLoss)
    relativeStrengthIndex = (100 - (100 / (1 + relativeStrength)))
    relativeStrengthIndex

Overview

RSI Lib measures bar-to-bar change, separates gains and losses, smooths both with a running moving average, and returns the standard 100-scale RSI. Callers pass the lookback length; the source is fixed to close and there are no inputs, plots, alerts, or trade rules. It does not draw on a chart by itself, even though the library declaration sets overlay to true.

Details

Published by

augustoerni on GitHub

Draws

Library (no plots)

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.

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

TrendChecker

by RobACurtis
1 stars

A Pine library that exports three functions, bullish, bearish and getTrend, which judge market direction on the current symbol and timeframe. Each call takes three switches to include a Stochastic RSI cross, a MACD line versus signal check and a comparison of

Library v5 TrendOscillators & momentum
Updated 2 years ago · None stated GitHub repository of TrendChecker
3 stars

This Pine Script v5 library exports detectYinYangCrown, which builds a standard MACD from close using caller-supplied fast, slow, and signal lengths. It tracks histogram color and a small state machine: a green histogram that rises to a peak, then declines, th

Library v5 Oscillators & momentum
Updated 7 weeks ago · None stated GitHub repository of YZM YinYang Crown Library

MirPapa_Lib_trend

by alvinng214
2 stars

MirPapa_Lib_trend is a Pine Script utility library providing trend and momentum calculation functions for other scripts. It features implementations for several moving average types, including the Hull Moving Average (HMA), Exponential Hull Moving Average (EHM

Library v6 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of MirPapa_Lib_trend

Momentum

by Electrified-Trading
2 stars

This Pine Script library calculates various momentum metrics and oscillator values for other scripts to use. It provides functions for standard-deviation-normalized price change, dual-moving-average momentum, Stochastic RSI, and a customizable MACD. Function p

Library v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum

ta

by ivansoft
1 stars

Provides a collection of technical analysis calculation functions for use across Pine scripts. It exports implementations for various indicators and mathematical formulas, including oscillators like the Awesome Oscillator, Aroon, and Schaff Trend Cycle, moving

Library v5 TrendOscillators & momentum
Updated 1 year ago · None stated GitHub repository of ta

FunctionLinearRegression

by ricardosantos79
261 stars

This Pine Script v5 library provides functions to calculate and plot linear regression channels using sample point arrays. It evaluates paired X and Y arrays to calculate the regression slope, intercept, fitted values, maximum deviation, minimum deviation, and

Library v5 Trend
Updated 4 years ago · None stated GitHub repository of FunctionLinearRegression

More Oscillators & momentum 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