Assign Value Color when Between 2 Values


Category:
0
0

Hello again.  Im trying to add a second assign value color line  for when the value is between two values.   I have value colors for when above 10 and below -10. But would like to know how to assign value colors when at/between -5 and -10, and 5 and 10. Heres the first Assign Color Values and my attempt a second.   Searching Learning Center, not sure how to express..  Any help is appreciated

Data.AssignValueColor (if Data<-10 then createColor(225,114,233) else if Data>10 then createcolor (231,190,0) else CreateColor(10,10,10));

Data.AssignValueColor ( if Data <= -5 and >=-10 then color.Dark_Grey else if Data>=5 and <=10 then Color.Dark_Grey else CreateColor(10,10,10));

Marked as spam
Posted by (Questions: 11, Answers: 15)
Asked on October 19, 2020 7:09 pm
409 views
0
Private answer

The AssignValueColor() function can only be called once for each plot. So you have two choices. You can split your plot into two distinct statements:

plot dataOne;

plot dataTwo;

Or you can fold the logic for all four level/color combinations into a single plot.

The logic to fold all four levels into one if/then/else statement should look something like this:

if data >= 10 then Color.WHITE else if data >= 5 then Color.YELLOW else if data >= -5 then Color.ORANGE else if data >= -10 then Color.RED else Color.DARK_RED

And if you wanted to see this applied to a fully functional solution you can use the following code to build a custom version of the AwesomeOscillator:

plot data = Average(hl2, 5) - Average(hl2, 34);
data.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
data.AssignValueColor(if data >= 10 then Color.WHITE else if data >=5 then Color.YELLOW else if data >= -5 then Color.ORANGE else if data >= -10 then Color.RED else Color.DARK_RED);

You can apply this to a custom chart study or a custom watchlist column. Please keep in mind that in this Q&A Forum we strive to make sure each and every post provides a fully functioning section of code. Which enables the broadest possible audience to make use of each and every solution posted.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 19, 2020 8:22 pm