Boolean Input

Yaser Rahmati | یاسر رحمتی

Goals

  • This Pine Script indicator allows the user to choose between two colors (color.green or color.red) based on a boolean input (value).

  • The default color is color.green when the boolean input (value) is true, and color.red when it's false.

  • The script then plots the closing price (close) using the selected color on the chart.

Pine Script Code

//@version = 5
indicator("Input Boolean")

value = input.bool(defval = true, title = "Change Color: Yes/No")

myColor = if(value == true)
	color.green
else
	color.red

plot(close, color = myColor)

Code Output

Explanation

//@version = 5
  • Specifies that the script is written in Pine Script version 5.

indicator("Input Boolean")
  • Defines the script as an indicator with the name "Input Boolean". This name will be displayed on the chart.

value = input.bool(defval = true, title = "Change Color: Yes/No")
  • Creates a boolean input variable named value.

  • defval = true: Sets the default value of value to true.

  • title = "Change Color: Yes/No": Specifies the label for the input field, prompting the user to choose "Yes" or "No".

myColor = if(value == true) color.green else color.red
  • This block assigns a color based on the boolean value.

  • If value is true, myColor is set to color.green.

  • If value is false, myColor is set to color.red.

plot(close, color = myColor)
  • Plots the closing price (close) on the chart.

  • color = myColor: Specifies the color of the plot, which is determined by the myColor variable based on the boolean input value.

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, یاسر رحمتی

Last updated