Boolean Input
Yaser Rahmati | یاسر رحمتی
Goals
This Pine Script indicator allows the user to choose between two colors (
color.green
orcolor.red
) based on a boolean input (value
).The default color is
color.green
when the boolean input (value
) istrue
, andcolor.red
when it'sfalse
.The script then plots the closing price (
close
) using the selected color on the chart.
Pine Script Code
Code Output
Explanation
Specifies that the script is written in Pine Script version 5.
Defines the script as an indicator with the name "Input Boolean". This name will be displayed on the chart.
Creates a boolean input variable named
value
.defval = true
: Sets the default value ofvalue
totrue
.title = "Change Color: Yes/No"
: Specifies the label for the input field, prompting the user to choose "Yes" or "No".
This block assigns a color based on the boolean
value
.If
value
istrue
,myColor
is set tocolor.green
.If
value
isfalse
,myColor
is set tocolor.red
.
Plots the closing price (
close
) on the chart.color = myColor
: Specifies the color of the plot, which is determined by themyColor
variable 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
, یاسر رحمتی
Last updated