Boolean Input
FXC911 – Forex & Crypto News & Insights
Goals
This Pine Script indicator allows the user to choose between two colors (
color.greenorcolor.red) based on a boolean input (value).The default color is
color.greenwhen the boolean input (value) istrue, andcolor.redwhen it'sfalse.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 = 5Specifies 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 ofvaluetotrue.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.redThis block assigns a color based on the boolean
value.If
valueistrue,myColoris set tocolor.green.If
valueisfalse,myColoris set tocolor.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 themyColorvariable based on the boolean inputvalue.
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:
🚀 Finance & Trading Insights: fxc911.ir
🐦 Twitter: x.com/fxc911_official/
Last updated