Home » Pinescript Syntax » Indicator Function in Pine Script

Indicator Function in Pine Script

Photo of author
Published on

A fundamental aspect of writing scripts in Pine Script is the indicator() function. This function is crucial as it designates your script as an indicator and sets various properties related to it. Let’s dive deep into the syntax, arguments, and practical usage of the indicator() function in Pine Script.

Syntax of indicator()

The general syntax of the indicator() function is as follows:

indicator(title, shorttitle, overlay, format, precision, scale, max_bars_back, timeframe, timeframe_gaps, explicit_plot_zorder, max_lines_count, max_labels_count, max_boxes_count, max_polylines_count) → void

Breaking Down the Arguments

  1. title (const string): This is the main title of your script. It appears on the chart and becomes the default title when publishing the script.
  2. shorttitle (const string): Acts as the display name on charts. If specified, it replaces the title in chart-related windows. It’s optional and defaults to the title.
  3. overlay (const bool): Determines the placement of the indicator. If true, the indicator overlays the chart; if false, it appears in a separate pane. Default is false.
  4. format (const string): Defines the formatting of displayed values. Options include format.inherit, format.price, format.volume, and format.percent. It’s optional, with format.inherit as default.
  5. precision (const int): Specifies the number of decimal places for values. It’s a non-negative integer up to 16. The default is inherited from the chart’s symbol precision.
  6. scale (const scale_type): Sets the price scale. Options are scale.right, scale.left, and scale.none. scale.none is valid only with overlay = true. It defaults to the chart’s scale.
  7. max_bars_back (const int): Defines the historical buffer length for variables and functions. Default is 0, but Pine Script® automatically detects the necessary buffer size.
  8. timeframe (const string): Adds multi-timeframe capabilities. An empty string or timeframe.period represents the chart’s timeframe. It’s optional, defaulting to timeframe.period.
  9. timeframe_gaps (const bool): Manages indicator values on higher timeframe bars. true causes gaps with na values, while false fills gaps with the latest known value. Default is true.
  10. explicit_plot_zorder (const bool): Controls the rendering order of plots, fills, and hlines. When true, newer plots overlay older ones. Default is false.
  11. max_lines_count (const int): Sets the maximum displayed line drawings, with a range of 1-500. This count is approximate. Default is 50.
  12. max_labels_count (const int): Similar to max_lines_count, it sets the maximum label drawings displayed. Default is 50.
  13. max_boxes_count (const int): Determines the maximum box drawings displayed, ranging from 1-500. Default is 50.
  14. max_polylines_count (const int): Sets the maximum polyline drawings, ranging from 1-100. Default is 50.

Example Usage

Here’s a simple example to illustrate the use of indicator():

indicator("My script", shorttitle="Script")

In this example, the script is set as an indicator named “My script” with a short title “Script”. It plots the closing prices of the trading instrument.

Key Features and Takeaways

  • Functionality: The indicator() function is essential for defining the basic properties of your Pine Script.
  • Customization: It offers extensive customization options for how your script interacts with the chart.
  • Flexibility: You have control over aspects like overlay, scale, precision, and multi-timeframe functionality.
  • Enhanced Visuals: Through parameters like max_lines_count, max_labels_count, etc., you can manage the visual elements of your script effectively.


The indicator() function is a cornerstone in Pine Script programming, offering vast customization to tailor your scripts precisely to your trading needs. Understanding and effectively using this function is key to developing robust and efficient indicators in Pine Script.

Leave a Comment