In short I have an indicator that has multiple requirements for setting background colors and bar colors. All of this was fine until I wanted to add a small wrinkle to it.
Basically I have two lines (plots), one of which I call the signal line and the other the baseline, If a value is above one or the other then the background is blue and if it is below then background is red (this also goes for barcolor if people so wish to have bar coloring on). I have two separate boolean inputs for each of these two lines so that the background color or bar color is colored depending on what the user prefers. I also have a boolean for bar colors just when the value crosses up or down one of the two lines, but we'll ignore that to keep this simpler.
One of the two lines I mentioned above is a moving average (signal line) of the values being measured by the indicator. I want to add a boolean input that if true only colors the bars or background IF the signal line is increasing and not if it is decreasing.
So, if value is above signal line or baseline AND signal line is rising then color background blue, and if not, red. The problem I've run into is that regardless of the signal line rising being true, if the indicator value is above the signal or baseline then the background or bars are always going to be colored in those areas. What I want is if the boolean input for the rising signal line is true then it ONLY colors behind those areas where it is true and no other areas. If that makes sense. Problem is it always colors for areas where the indicator value is above the signal/baseline regardless if the signal line is rising or not, even if the boolean for a rising signal line is true, which defeats the purpose of having this rising signal line requirement.
I'm going to add the pertinent code below. If someone could help that would be wonderful. I can't figure out how to make a negation of background colors and bar colors, which it seems is what I need? The only other alternative I can think of (because I'm an awful coder) is to have separate boolean inputs for 'if value is above signal line' and 'if value is above signal line and signal line is rising' and 'if value is above baseline' and 'if value is above baseline and signal line is rising', plus bar coloring and the crossing up or down vs. being simply above or below. This would make for a grand total of 16 boolean inputs, which is insane obviously.
//BAR COLOR AND BACKGROUND COLOR SIGNAL LINE INPUTS
barcolor_signal = input.bool(defval=false, title='Bar Colors', group='Signal Line')
bg_signal = input.bool(defval=false, title='Background Colored', group='Signal Line')
xover_signal = input.bool(false, 'Volatility Advance', group='Signal Line')
xunder_signal = input.bool(false, 'Volatility Decline', group='Signal Line')
//BAR COLOR AND BACKGROUND COLOR BASELINE INPUTS
barcolor_bline = input.bool(defval=true, title='Bar Colors', group='Baseline')
bg_bline = input.bool(defval=false, title='Background Colored', group='Baseline')
xover_bline = input.bool(false, 'Volatility Advance', group='Baseline')
xunder_bline = input.bool(false, 'Volatility Decline', group='Baseline')
////BOOLEAN
signal_rise = input.bool(defval=true, title='Require Signal Line Rising', tooltip='Require the signal line to be rising to highlight increasing volatility.')
For the inputs, the first group is for if the value is above/below or crossing the signal line, the second group is for if the value is above/below or crossing the baseline, and the last input is signal line rising input.
///BACKGROUND AND CANDLE COLORING
sig_rise = signal_rise and signal_line > signal_line[1]
bline_rise = avg_range > baseline
bline_fall = avg_range < baseline
avg_sig_rise = avg_range > signal_line
avg_sig_fall = avg_range < signal_line
bgcolor(bg_bline and bline_rise ? color.new(#445b84, 50) : bg_bline and bline_fall ? color.new(#844444, 100) : na, title='Baseline Background')
bgcolor(sig_rise and bg_bline and bline_rise ? color.new(#445b84, 50) : sig_rise and bg_bline and bline_fall ? color.new(#844444, 100) : na, title='Baseline Background | Signal Line Rising')
bgcolor(bg_signal and avg_sig_rise ? color.new(#445b84, 50) : bg_signal and avg_sig_fall ? color.new(#844444, 100) : na, title='Signal Line Background')
bgcolor(sig_rise and bg_signal and avg_sig_rise ? color.new(#445b84, 50) : sig_rise and bg_signal and avg_sig_fall ? color.new(#844444, 100) : na, title='Signal Line Background | Signal Line Rising')
I'm not adding the code for barcolor because whatever solution there is should work for that too I would think.
You can see in the first line for bgcolor that that is the simplest--if background is true and avg_range is above baseline then COLOR. The one below requires the signal line to be rising, and the two below are if the avg_range is above the signal line.
I need for the first and third lines to be false if the second or fourth are true, OR I need another way to write this.
Appreciate any help with this.