Show only odd or even bar numbers


Category:
0
0

Hi Pete, the following code shows the bar number below the bars. For a 2 min chart it will show numbers 1 to 203 for RTH. Is there a way to create an input field value (even/odd) so you can select even/odd and show only even bar numbers or odd bar numbers? (–> This will result in showing numbers every other bar either starting on 1 or 2)

plot barNum = 1 + (SecondsFromTime(0930) / 120);
barNum.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barNum.SetDefaultColor(Color.BLACK);

RESOLVED
Marked as spam
Posted by (Questions: 2, Answers: 2)
Asked on April 22, 2022 2:03 pm
212 views
0
Private answer

I could not see a connection between the title you selected for the question and the end result you are seeking.

Original title: "Show bar number based on number type"

So I updated the title of the question to describe the context as I understand it.

If you want to add a user input and sections of code to enable this to display only odd numbers or only even numbers this is the solution. I have updated the default color so that it will work with the majority of users. Most users will select either a white or black background for their charts so I selected Gray as the default color.

input oddOrEven = {default Odd, Even};
def factor = 2;
def barNumber = 1 + (SecondsFromTime(0930) / 120);
def adjustedBarNumber = if oddOrEven == oddOrEven.Even then
if barNumber % factor == 0 then barNumber else Double.NaN else
if barNumber % factor > 0 then barNumber else Double.NaN;
plot barNum = adjustedBarNumber;
barNum.SetPaintingStrategy(PaintingStrategy.VALUES_BELOW);
barNum.SetDefaultColor(Color.GRAY);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on April 22, 2022 8:12 pm
0
Thank you Pete!!!! (Blowing My MIND! 👍 👍 👍)
( at April 23, 2022 4:07 pm)