Home » Technical Analysis Functions » Understanding ta.falling() Function in Pine Script

Understanding ta.falling() Function in Pine Script

Photo of author
Published on

In this article, we’re diving deep into the ta.falling() function in Pine Script, a powerful tool for technical analysis in trading. Pine Script is the scripting language used on the TradingView platform, allowing users to create custom indicators, strategies, and scripts. The ta.falling() function is particularly useful for identifying downtrends in a data series, making it invaluable for traders looking to capitalize on bearish market movements.

Syntax and Arguments

The ta.falling() function is structured as follows:

ta.falling(dataSeries, periodLength) → series bool
  • dataSeries (series int/float): This is the series of values that you want to analyze. It could be the closing price of a stock, the volume, or any other numerical data that can be represented as a series.
  • periodLength (series int): This represents the number of bars, or periods, over which you want to check if the series is falling.


The function returns a boolean series:

  • true if the current value in dataSeries is less than any of its previous values for periodLength bars back.
  • false otherwise.


Let’s create a simple indicator that highlights bars where the closing price has been falling for the last 5 bars.

indicator("Falling Price Example", overlay=true)

// Define the length for the falling check
periodLength = 5

// Check if the close price has been falling for the last 5 bars
isFalling = ta.falling(close, periodLength)

// Plotting
bgcolor(isFalling ? color.red : na, title="Falling Background")

In this example:

  • periodLength is set to 5, meaning we’re looking for a falling trend over the last 5 bars.
  • isFalling uses the ta.falling() function to check if the closing price (close) has been falling over the specified period.
  • bgcolor() changes the background color of bars where isFalling is true to red, visually indicating a falling price trend.

Detailed Walkthrough

  1. indicator() Declaration: The script begins with the indicator() function, which defines the script as a custom indicator and sets its properties. Here, overlay=true allows the indicator to be plotted directly on the price chart.
  2. Defining periodLength: We specify how many bars to look back to check for a falling trend. In this case, we’re interested in a short-term downtrend of 5 bars.
  3. The ta.falling() Function: This is where we check if the closing price has been consistently lower than its previous values for the last 5 bars. It returns a series of boolean values (true or false) for each bar.
  4. Plotting with bgcolor(): We use the bgcolor() function to change the background color of bars where the price has been falling, making these trends easy to spot visually.

Key Features

  • Function Usability: The ta.falling() function is versatile and can be used with any data series, not just price. It can help identify downtrends in volume, indicators, or any custom series.
  • Syntax and Application: Understanding the syntax is crucial for effective application. The function requires two arguments: the data series and the length of the period to analyze.
  • Practical Utility: This function is invaluable for traders and analysts looking to identify bearish trends without manually scanning charts. It can be integrated into broader trading strategies or used to trigger alerts.


  • ta.falling() is a boolean function in Pine Script that helps identify downtrends over a specified period.
  • The function takes two arguments: a data series to analyze and the length of the period.
  • It is particularly useful for traders looking to spot bearish trends and can be applied to any numerical data series.
  • The example provided demonstrates a practical application by highlighting bars with a falling closing price over the last 5 bars.

Understanding and utilizing the ta.falling() function can significantly enhance your technical analysis and trading strategies on the TradingView platform.

Leave a Comment