Use paintbar on the current candle/bar only.


Category:
0
0

I use grey for my down candles. I use blue for my up candles. I color the current candle red, yellow or green based on the buying volume percentage. The only problem is that the chart displays the red, yellow or green colors on the previous candles where that “paintbar” condition was met. I want the previous candles to go back to the grey or blue color and only color the current candle.

#———- Condition
def paintBar = buyVolPercent between 81 and 100;
def paintBar1 = buyVolPercent between 51 and 80;
def paintBar2 = buyVolPercent between 0 and 50;

#———- Paint Candles
AssignPriceColor(if paintBar then CreateColor(10,127,72) else Color.Current);
AssignPriceColor(if paintBar1 then CreateColor(175,175,0) else Color.Current);
AssignPriceColor(if paintBar2 then CreateColor(185,40,40) else Color.Current);

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on December 21, 2020 2:50 pm
110 views
0
Private answer

I moved your question out of the "Frequently Asked Questions" topic and into the "Chart Studies" topic.

Here is the solution to: "Use paintbar on the current candle/bar only"

def condition = close > open;
def lastBar = !IsNaN(close) and IsNaN(close[-1]);
AssignPriceColor(if lastBar and condition then Color.GRAY else Color.CURRENT);

I think that solution will have the broadest possible application, for those that are comfortable writing their own scripts. This shows the basic concept in a form that can be very easily applied to just about any signal someone might want to display only on the last bar of the chart.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on December 21, 2020 3:18 pm
0
Thanks for the quick reply. It works great!
( at December 21, 2020 6:22 pm)