How to Create an Indicator in TradingView Pine Script: Building a Custom RSI

Technical trading indicators are essential tools for traders seeking to analyze market conditions and make informed decisions. In this article, we explain what these indicators are, discuss the benefits of using them, and guide you through creating a custom Relative Strength Index (RSI) indicator in Pine Script—with all parameters configurable and key levels plotted.

What Is a Technical Trading Indicator and Its Benefits

A technical trading indicator is a mathematical calculation based on historical price, volume, or open interest data. These indicators help traders to:

  • Identify Trends: Determine whether the market is trending up, down, or sideways.
  • Assess Momentum: Understand the strength behind price movements.
  • Spot Overbought/Oversold Conditions: Signal when prices may be due for a reversal.
  • Support Entry and Exit Decisions: Provide visual signals that can complement your trading strategy.


By using these tools, traders can reduce uncertainty and base their decisions on historical patterns and statistical analysis, rather than solely on subjective judgment.

A Brief Overview of the RSI Indicator

The Relative Strength Index (RSI) is one of the most popular momentum oscillators. It measures the speed and change of price movements and is typically used to identify overbought or oversold conditions in a market. Here’s what you need to know:

  • Calculation: RSI compares the magnitude of recent gains to recent losses over a specified time period (commonly 14 periods).
  • Interpretation: Traditionally, RSI values above 70 suggest that a security may be overbought, while values below 30 indicate oversold conditions. However, in our custom version we will set overbought and oversold levels at 80 and 20, respectively.
  • Market Suitability: RSI is particularly useful in markets that show clear momentum shifts, including stocks, forex, and cryptocurrencies. It is best applied in markets where price swings are pronounced enough to signal potential reversals.

Creating and Plotting a Custom RSI Indicator in Pine Script

TradingView’s Supercharts

Figure 1. Custom RSI Indicator In Pine Script with Configuration Window

Pine Script is TradingView’s powerful scripting language that allows you to create custom indicators and strategies. Below is a step-by-step guide and code snippet to build an RSI indicator with configurable parameters and custom levels.


Step 1: Setting Up the Indicator


Begin by defining the script version and indicator properties. In Pine Script version 5, you can create a standalone indicator that isn’t overlaid on the price chart (i.e., it has its own pane).


Step 2: Configurable Parameters


Make parameters like the RSI length, source (typically closing price), and threshold levels adjustable via the input function. This flexibility allows you to tweak the indicator settings directly from the chart interface.


Step 3: Calculating and Plotting RSI


Compute the RSI value using the built-in ta.rsi() function. Then, plot the RSI line, along with horizontal lines marking key levels:

  • A zero line (though RSI normally ranges from 0 to 100, including a zero line can be helpful for visual reference).
  • An overbought line at 80.
  • An oversold line at 20.


Below is the complete Pine Script code for our custom RSI indicator:


//@version=5

indicator("Custom RSI Indicator", overlay=false, shorttitle="RSI")

// Configurable parameters

rsiLength = input.int(14, minval=1, title="RSI Length")

src = input(close, title="Source")

overbought = input.int(80, title="Overbought Level")

oversold = input.int(20, title="Oversold Level")

// Calculate RSI

rsiValue = ta.rsi(src, rsiLength)

// Plot the RSI

plot(rsiValue, color=color.blue, title="RSI")

// Plot reference lines: zero, overbought, and oversold

hline(0, "Zero Line", color=color.gray)

hline(overbought, "Overbought", color=color.red)

hline(oversold, "Oversold", color=color.green)


Explanation of the Code:

  • Script Declaration: //@version=5 ensures the script uses the latest Pine Script features.
  • Indicator Setup: The indicator() function declares the script as an indicator with a custom name and specifies that it should appear in its own pane (overlay=false).
  • Inputs: input.int() and input() functions let users configure the RSI length, source price, and threshold levels directly from the TradingView interface.
  • RSI Calculation: The ta.rsi() function computes the RSI value using the selected parameters.
  • Plotting: The plot() function displays the RSI line, and hline() functions draw horizontal lines at the zero, overbought, and oversold levels.

Conclusion: The Power of Custom Technical Indicators in Pine Script

Developing your own indicators in Pine Script not only gives you a better understanding of technical analysis but also empowers you to tailor your tools to fit your trading style. With a few lines of code, you can create a highly configurable RSI indicator that highlights key market signals—helping you spot potential trading opportunities and manage risk more effectively.


By learning Pine Script and leveraging custom indicators like this one, traders can refine their strategies and gain a competitive edge in dynamic markets. Whether you’re trading stocks, ETFs, or cryptocurrencies, the ability to code your own indicators is an invaluable skill for any technical analyst.

Sergey Buzz