How To Color An Indicator?

FXC911 – Forex & Crypto News & Insights

Goals

The script plots two lines on the chart:

  • The close price in green.

  • The open price in red with 75% transparency.

Pine Script Code

//@version=5
indicator("Indicator Color")

plot(close, color=color.green)
plot(open, color=color.new(#ecf012, 10))

Code Output

Explanation

1. Version Declaration:

//@version=5
  • This line specifies that the script is written in Pine Script version 5.

2. Indicator Declaration:

indicator("Indicator Color")
  • This line defines a new indicator named "Indicator Color". When this script is applied to a chart, this name will be shown in the list of applied indicators.

3. Plotting Close Value with Color:

plot(close, color=color.green)
  • plot(close, color=color.green): The plot function is used to draw a plot on the chart.

  • close: This is a built-in variable in Pine Script that represents the closing price of the current bar.

  • color=color.green: This specifies that the plot of the close price will be colored green.

4. Plotting Open Value with Color and Transparency:

plot(open, color=new(color.red, 75))
  • plot(open, color=new(color.red, 75)): The plot function is used to draw a plot on the chart.

  • open: This is a built-in variable in Pine Script that represents the opening price of the current bar.

  • color=new(color.red, 75): This creates a new color based on color.red with 75% transparency. The new function allows customization of the color, including setting its transparency. The transparency value ranges from 0 (fully opaque) to 100 (fully transparent).

Keywords

pine script, trading view, script editor, indicators, strategies, backtesting, alerts, custom scripts, stock analysis, charting tools, technical analysis, built-in functions, pine script syntax, trading bots, automated trading, scripting language, market data, trading signals, financial markets, programming trading strategies

Visit me on:

Last updated