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

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

pine script - Keeping bar colors same until another condition occurs in pinescript

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...