Home » Input Functions » Input.color Function In Pinescript

Input.color Function In Pinescript

Photo of author
Published on

Pine Script is a domain-specific language developed by TradingView, used for scripting strategies and indicators in the TradingView platform. The language is versatile, powerful, and easy to use. One of its crucial features is the input.color() function.

In this tutorial, we will delve into the input.color() function, covering its purpose, syntax, arguments, and usage. We’ll also include a unique use-case example to help you understand how to leverage this function in your scripts.

Understanding the input.color() Function

The input.color() function is a built-in function in Pine Script, which adds a color input to the Inputs tab of your script’s Settings. This feature enables users to configure the color and transparency options in your script. It can either be selected from a palette or directly from a hex value.

The syntax for input.color() function is as follows:

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

Let’s break down the arguments:


  • defval (const color): This is the default color value for the input variable. Users can change this value in the “Settings/Inputs” tab of the script.
  • title (const string): This is the title of the input. If not provided, Pine Script uses the variable name as the title.
  • tooltip (const string): This is the tooltip string displayed to the user when they hover over the tooltip icon.
  • inline (const string): This argument allows you to combine all the input calls in one line, using the same string argument.
  • group (const string): This creates a header above all inputs using the same group argument string.
  • confirm (const bool): If set to true, the user will be asked to confirm the input value before adding the indicator to the chart. By default, it’s set to false.

Example Usage of input.color()

Let’s understand the usage of input.color() through a practical example.

indicator("input.color Example", overlay=true)
bullColor = input.color(color.rgb(245, 245, 245), "Bullish Candle Color")
bearColor = input.color(color.rgb(82, 137, 255), "Bearish Candle Color")
colorCond = close > open ? bullColor : bearColor
plotcandle(open, high, low, close, color=colorCond)
input.color function

This script creates an indicator that colors the candlesticks based on their direction. The color is chosen by the user via the Inputs tab in the settings.

  • First, we define two color inputs, bullColor for bullish (rising) candles, and bearColor for bearish (falling) candles. The user can change these colors in the script’s “Settings/Inputs” tab.
  • Next, we define colorCond, which decides the color of each candlestick. If the closing price is higher than the opening price (a bullish candle), colorCond is set to bullColor. Otherwise, it’s set to bearColor.
  • Finally, we use plotcandle() function to plot the candlestick chart, passing the colorCond variable to the color parameter. This colors each candlestick based on its direction.

Key Takeaway

The input.color() function is an invaluable tool for script customization in Pine Script. It offers users the ability to select their preferred color and transparency settings for specific components of a script, enhancing user interactivity and overall experience.


Pine Script’s input.color() function is a testament to the language’s user-friendly design and adaptability. By mastering this function, you’ll add a new level of customization and flexibility to your scripts, improving user satisfaction and engagement.

Whether you’re plotting indicators, drawing shapes, or coloring bars, the input.color() function brings color customization right to your fingertips. We hope this tutorial sheds light on its usage and aids in your Pine Script programming journey. Happy scripting!

Leave a Comment