because you assign the red color to buffer index 1 and the condition i>=5 will always be true after the very first 5 bars exist
But the condition is working right. I printed the log of results, Color Index Changed after Bar 5. But that does not show on the chart
2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 0 Color Index: 2.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 1 Color Index: 2.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 2 Color Index: 2.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 3 Color Index: 2.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 4 Color Index: 2.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 5 Color Index: 1.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 6 Color Index: 1.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 7 Color Index: 1.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 8 Color Index: 1.0 2025.02.24 12:26:34.481 (USDJPY,H1) Bar: 9 Color Index: 1.0
Because the first 5 bars is so far back in time that it probably won't be visible on the chart at all. In terms of correctness, the code itself is working fine as far as I can see. Those dates seem wrong and I don't know how you are printing it. If you want bar 0 to 5 to be from newest to oldest then you can set buffers as series
You are telling the terminal "if you are above the 10th bar in the entire chart set d2 to 1"
so you are limiting the colors to 2 when the line is uncommented.
This is true for 99.9% of the chartThe counter starts from 0 and up. It will be under 10 with the first 10 candles.
What's wrong with the logic?
if you mean the 10 bars from the right then change it to
if (i<(rates_total-10)) d2=0; else d2=1;
bar [0] is the oldest
But then you will also have to paint the bar that slides out of the 10 bars rangePlease don't post the same topic multiple times. Post only once and in a relevant thread or forum section.
I have merged your two separate topics into just this one.
And when posting log output please also use the CODE button (Alt-S), just as is the case of source code.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use


last 2 lines in this code, Tow almost identical IF condition.
The first draw candles in one color which is not the required output.
The second if you removed the remark "//" will show candles in 2 colors
The task simply is to show the first 5 candles in different colors.
What can I do?
Thank you.