'Change color of the 7th bar only - (specific candle color Tradingview)
I would like to change the color of a single candle. For example only the 7th.
I tried with barcolor and offset but it also points out all the previous ones of 7, Can you help me to get only the 7th bar in yellow ?
//@version=5
indicator('Previous Candle High and Low', shorttitle='Prev. H/L', overlay=true)
dt = time - time[1]
patternLabelPosHigh = close[7]
barcolor(color=bar_index ? color.yellow : na, offset=-6)
Thank you !
Solution 1:[1]
If you would like to retroactively paint only the 7th bar to the left and redraw the results, you have to check the current bar's state.
The construction below looks redundant, however it covers all possible states of the market as far as I tested, the script below will constantly paint 7th bar to the left and redraw on every new bar:
//@version=5
indicator("Past barcolor()")
pastBar = input.int(7, title = "Past Bar", minval = 1)
barcolor((barstate.islast or barstate.isrealtime) and (not barstate.isconfirmed or barstate.islastconfirmedhistory) ? color.new(color.blue, 0) : na, offset = - pastBar)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | e2e4 |

