Home » Input Functions » input.time function in Pine Script

input.time function in Pine Script

Photo of author
Published on

Pine Script, offers a multitude of functions that aid developers in creating custom technical analysis tools. One such function is input.time, which adds a time input to your script’s “Settings/Inputs” tab. This feature is crucial when creating scripts that need to consider specific time points. This blog will give you a thorough walkthrough on how to use this function effectively, starting with its syntax, followed by a unique use-case example, and finally, key takeaways.

Function Syntax and Parameters

The input.time function in Pine Script is invoked with the following syntax:

input.time(defval, title, tooltip, inline, group, confirm) → input int

Each parameter plays a unique role, and here is what they represent:

  1. defval (const int): This determines the default value of the input variable. This value can be a timestamp function, provided it uses a date argument in const string format.
  2. title (const string): This represents the title of the input. If not specified, the variable name is used as the input’s title. If the title is specified but is empty, the name will be an empty string.
  3. tooltip (const string): This string is shown to the user when hovering over the tooltip icon.
  4. inline (const string): This combines all the input calls using the same argument in one line. The string used as an argument is not displayed, it is only used to identify inputs belonging to the same line.
  5. group (const string): This creates a header above all inputs using the same group argument string. The string is also used as the header’s text.
  6. confirm (const bool): If true, the interactive input mode is enabled and the selection is done by clicking on the chart when the indicator is added to the chart.

A Unique Use Case Example

To make this concept clearer, let’s go through a unique use-case. We’ll create a script that identifies the high of a selected date and labels it.

indicator("input.time", overlay=true)
i_date = input.time(timestamp("20 May 2023 00:00 +0300"), "Date")
l = label.new(i_date, high, "Date" , xloc=xloc.bar_time , size = size.large)

Here’s what each line of the script does:

  1. //@version=5: This line is specifying the version of Pine Script to use, in this case, version 5. It is important to denote the script’s version at the beginning of your script since different versions may have different functions and syntax.
  2. indicator("input.time", overlay=true): This line is calling the indicator function to set up a new indicator with the title “input.time”. The parameter overlay=true ensures that this indicator will be drawn directly on the price chart.
  3. i_date = input.time(timestamp("20 May 2023 00:00 +0300"), "Date"): This line uses the input.time function to create an input in the settings tab with a default timestamp of “20 May 2023 00:00 +0300”. The user can modify this time input in the settings tab of the script. The “Date” argument serves as the title for this input.
  4. l = label.new(i_date, high, "Date" , xloc=xloc.bar_time , size = size.large): This line creates a new label on the chart at the bar corresponding to the input date i_date. The y-coordinate of the label is determined by the high price of that bar. The label’s text will be “Date”, and it will be displayed at the time of the bar (xloc=xloc.bar_time). The label size will be large (size = size.large).
  5. label.delete(l[1]): This last line ensures that only the most recent label is displayed on the chart. It deletes the previous label before drawing the new one.

Key Takeaways

input.time is a powerful tool in Pine Script that allows users to interact with the chart by selecting a specific point in time. This function opens up a range of possibilities for custom scripts that need user-selected time inputs.

Remember, while using the input.time function:

  • You can combine a price input with a time input if both function calls use the same argument for their inline parameter.
  • Interactive mode (enabled by setting confirm = true) allows users to select a point in time directly on the chart.


The input.time function adds a significant degree of interactivity and flexibility to your Pine Script tools. As we’ve seen in our unique use case, the function can be employed to enhance user experience and provide additional customization options. Don’t hesitate to explore this function further, incorporate it into your scripts, and make the most of its potential.

Leave a Comment