I'm writing this simple code with 2 ATRs and added a black barcolor when the candle exceeds a set percentage of ATR both as high-low or as close-open.
I'm now trying to highlight the following candle in yellow if it does retrace but in case this second candle as well exceeds the ATR percentage, I'd like it to paint black rather than yellow.
In simple words, I'd like the black barcolor to always have the priority over the yellow one.
Unluckily I'm doing something wrong and the code only paints the black bars and not the yellow ones. Hopefully some of you will be able to help me.
Thanks in advance
//@version=4
study("ATRs", shorttitle="ATRs", overlay=false, precision=5)
length=input(14, title="ATR Length")
vaexocco=input(150, title="OCCO Exceeding %", step=5)
vaexhl=input(200, title="HL Exceeding %", step=5)
brcl=input(true, title="Color Bars")
mult=input(0.7, title="Percentage Multiplier (for ex., 0.7 = 70%)", step=0.1, minval=0.1, maxval=2.0)
x=0.0
y=syminfo.pointvalue==0
w=y?atr(length):(syminfo.pointvalue * mult * atr(length))
x:=y?(nz(x[1])+0.7)%3.0:na
p1 = plot(rma(tr(true), length), color=#ff6d00, linewidth=1, transp=100, title="1xATR")
plot(y?na:w, color=color.blue, linewidth=1,transp=100, title="ATR")
//Bar Color
occo = close > open ? close - open : open - close
mtatr = high-low > vaexhl/100*atr(length)[1] or occo > vaexocco/100*atr(length)[1]
brclr = color.black
bar_dir = close[1] > open[1] ? 1 : open[1] > close[1] ? -1 : na
a = bar_dir == -1 ? (close > close[1]) : bar_dir == 1 ? (close < close[1]) : na
b = bar_index[1] == mtatr and bar_index == a
fnl = (mtatr and b ? color.black : mtatr ? color.black : b ? color.yellow : na)
wch_ = brcl ? fnl : na
barcolor(wch_)
This will hopefully get you closer to your objective: