Home » Technical Analysis Functions » ta.highest Function in Pine Script

ta.highest Function in Pine Script

Photo of author
Published on

In the realm of technical analysis with Pine Script, the ta.highest function is a powerful tool that often goes underutilized. In this tutorial, we’ll dive deep into this function, exploring its syntax, arguments, and use-cases to elevate your Pine Script game.

Syntax and Overloads

Basic Syntax

The ta.highest function has two different overloads. The first takes only a length argument, and the second takes a source series and a length:

  1. ta.highest(length) → series float
  2. ta.highest(source, length) → series float

Arguments Explained

Length Argument

The length argument specifies the number of bars back to consider for finding the highest value. It’s a simple integer value, and this is a mandatory argument.

Source Argument

The source argument is optional and specifies the data series to look through when finding the highest value. If you don’t specify the source, the function uses the high prices (high) of bars as the default series.

How It Works

The function scans through the data series (or high prices by default) over the specified length and returns the highest value within that range. Any na (not applicable) values in the series are ignored.

Unique Use-Case Example

Let’s delve into a use-case where we use ta.highest to identify resistance levels in a trading range.

indicator("Resistance Identifier", overlay=true)

length = 50
source = close

// Calculate Highest Close price
highestClose = ta.highest(source, length)

// Plot resistance levels
plotshape(series=ta.barssince(highestClose == source) == 0, title="Resistance", location=location.belowbar, color=color.red, style=shape.labelup, text="Resistance")
ta.highest Function in Pine Script

Here’s what each line of code does:

  1. //@version=5: Specifies the Pine Script version.
  2. indicator("Resistance Identifier", overlay=true): Creates a new indicator with the name “Resistance Identifier” that overlays the price chart.
  3. length = 50: Sets the length to look back 50 bars.
  4. source = close: Uses the close prices of the bars as the source series.
  5. highestClose = ta.highest(source, length): Finds the highest close price in the last 50 bars.
  6. plotshape(...): Plots a label below the bar whenever a new resistance level is identified, which is when the highest close price is equal to the current close price.

Key Takeaway

The ta.highest function is versatile and essential for various types of market analysis. It allows you to easily identify the highest value in a specific series over a defined length of bars, making it easier to pinpoint resistance levels, among other things.


Understanding how to use ta.highest in Pine Script can significantly enhance your trading strategies. The function’s flexibility in accepting different arguments and its ability to ignore na values make it a powerful addition to your Pine Script toolbox. Armed with this knowledge, you’re now ready to tackle more complex trading algorithms and indicators. Happy coding!

Leave a Comment