Display indicator status as colored bar


Category:
0
0

Looking for an example of a way to show a lower study as a simple horizontal bar that would be different colors based on the status of the indicator. Attaching a jpg for the idea. Any guidance appreciated. Thank you!

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on May 25, 2021 10:07 am
70 views
0
Private answer

Since you did not include any specific details you wanted to include I made up my own set of three conditions. The solution I am providing plots squares on the lower subgraph. (Histogram is something entirely different).

Rows are numbered 0 through 2. Row zero shows green for up bars and red for down bars. Row one displays green when there is a higher high and higher low, red when there is a lower high and lower low, and gray for all other conditions. Row 3 displays yellow for inside bars and gray for other conditions.

Here is the code:

declare lower;
def upBar = close > close[1];
def higherHighLow = high > high[1] and low > low[1];
def lowerHighLow = high < high[1] and low < low[1];
def insideBar = high < high[1] and low > low[1];
plot rowOne = if !IsNaN(close) then 0 else Double.NaN;
rowOne.SetPaintingStrategy(PaintingStrategy.SQUARES);
rowOne.SetLineWeight(4);
rowOne.AssignValueColor(if upBar then Color.GREEN else Color.RED);
plot rowTwo = if !IsNaN(close) then 1 else Double.NaN;
rowTwo.SetPaintingStrategy(PaintingStrategy.SQUARES);
rowTwo.SetLineWeight(4);
rowTwo.AssignValueColor(if higherHighLow then Color.GREEN else if lowerHighLow then Color.RED else Color.GRAY);
plot rowThree = if !IsNaN(close) then 2 else Double.NaN;
rowThree.SetPaintingStrategy(PaintingStrategy.SQUARES);
rowThree.SetLineWeight(4);
rowThree.AssignValueColor(if insideBar then Color.YELLOW else Color.GRAY);

Screenshot below shows what this looks like on the chart.

Edit: There is a comment below asking if there is a way to remove the spaces between the separate rows on the lower subgraph. Initially I did not believe it could be down. But later on the solution popped into my head out of the clear blue. Here it is:

declare lower;
def upBar = close > close[1];
def higherHighLow = high > high[1] and low > low[1];
def lowerHighLow = high < high[1] and low < low[1];
def insideBar = high < high[1] and low > low[1];
plot filler = if!IsNaN(close) then 0 else Double.NaN;
plot rowOne = if !IsNaN(close) then 1 else Double.NaN;
rowOne.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
rowOne.SetLineWeight(4);
rowOne.AssignValueColor(if upBar then Color.GREEN else Color.RED);
plot rowTwo = if !IsNaN(close) then 2 else Double.NaN;
rowTwo.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
rowTwo.SetLineWeight(4);
rowTwo.AssignValueColor(if higherHighLow then Color.GREEN else if lowerHighLow then Color.RED else Color.GRAY);
plot rowThree = if !IsNaN(close) then 3 else Double.NaN;
rowThree.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
rowThree.SetLineWeight(4);
rowThree.AssignValueColor(if insideBar then Color.YELLOW else Color.GRAY);

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on May 25, 2021 10:57 am
0
kewl. any way to close up the space between bars? changing line weight just makes the line smaller.
( at May 25, 2021 6:41 pm)
0
No there is no way to adjust that through any settings or code we can add.
( at May 25, 2021 7:18 pm)
0
I discovered a solution to that last bit of your request and I have updated my answer to include the updated section of code to remove the spaces between rows.
( at May 25, 2021 9:39 pm)