'multiple input.bool giving trouble

i'm new to programing and i'm having this problem i don't know the answer for. The point of this code is to find bars that have green and sidebar condition.

Ok, BAR = sidebar and green finds those two conditions on candles on the chart... and barcolor(BAR ? color.yellow : na) gives it a yellow paint on the graph or does nothing.

The issue i'm having is that i want to be able to turn on or off green and sidebar on BAR... I tried with the greenOn = input.bool(title="Green Candle", defval=true) to see if greenis off it will show only sidebar but instead it shows nothing at all. Can someone explain to me whats going on here?. I'm trying to make an input configuration that allows me to say if it shows only green or side bar or a combination of both.

I tried to google this but i'm having trouble for this exact problem. Please consider i'm new to this kind of problems, thanks in advance!

// © UvDanger

//@version=5
indicator("Boolean ex", overlay=true)

//USERINPUTS
greenOn = input.bool(title="Green Candle", defval=true)

//CANDLE CONDITIONS
green = greenOn ? open < close : na //.....................<--- Finds green bars
sidebar = high < high[1] and low > low[1] //<--- Finds inside bars


//CANDLE INDICATOR
BAR = sidebar and green //.........<--- trying to remove one or the other

//CANDLE
barcolor(BAR ? color.yellow : na) ```



Solution 1:[1]

Introduced a second input for the sidebar condition and used greenOk and sidebarOk as a switch,

//@version=5
indicator("Boolean ex", overlay=true)

//USERINPUTS
greenOn = input.bool(title="Green Candle", defval=true)
sidebarOn = input.bool(title="Sidebar Candle", defval=true)

//CANDLE CONDITIONS
green = open < close                      //<--- Finds green bars
sidebar = high < high[1] and low > low[1] //<--- Finds inside bars

//CANDLE INDICATOR
greenOk = greenOn ? green ? true : false : true
sidebarOk = sidebarOn ? sidebar ? true : false : true

BAR = greenOk and sidebarOk

//CANDLE
barcolor(BAR and (greenOn or sidebarOn) ? color.yellow : na)

You can also use the input.string with options and use the switch structure:

//@version=5
indicator("Boolean ex", overlay=true)

inputSwitch = input.string('Only Green Candle', 'Input Switch', options = ['Only Green Candle', 'Only Sidebar Candle', 'Green & Sidebar Candles'])

//CANDLE CONDITIONS
green = open < close                      //<--- Finds green bars
sidebar = high < high[1] and low > low[1] //<--- Finds inside bars

BAR = switch inputSwitch
    'Only Green Candle' => green
    'Only Sidebar Candle' => sidebar
    'Green & Sidebar Candles' => green and sidebar

//CANDLE
barcolor(BAR? color.yellow : na)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 e2e4