Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two different conditions that colors bars accordingly. If these two conditions aren't met, bar colors stay as default colors (or na). I am having a chart with bars as blue, blue, na, blue, na, yellow, na, yellow etc.

What I would like to do is to paint all bars with same color until second condition happens. Meaning that all bars will be blue until yellow bar appears and all bars will be yellow after blue bar appears.

As in below image, I want all gray bars between and around blue bars until first yellow bar appears, and vice versa

barcolors

question from:https://stackoverflow.com/questions/65861355/keeping-bar-colors-same-until-another-condition-occurs-in-pinescript

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

Cem,

I am new too. Its hard to assist without showing some code, maybe provide a section of the code.

But would you not just change the na to gray. Obs Up and Down would be defined.

barcolor(Up ? color.blue : Down ? color.yellow : color.gray, transp=70)

Try the below

UpCond = fastEMA[1]>slowEMA[1] and high>high[1]
DownCond = fastEMA[1]<slowEMA[1] and hist[1] < 0 and low<low[1]

barcolor(UpCond ? color.blue : DownCond ? color.yellow : color.gray, transp=70)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...