I want to develop a Trading View Indicator in which the Candle turns Blue if TR<ATR. I tried the below code but no result.
//@version=5
indicator("TR < ATR Color Change", overlay=true)
// Calculate True Range (TR)
tr = math.abs(high - low)
tr += math.max(math.abs(high - close), math.abs(low - close))
// Calculate Average True Range (ATR)
atr = math.avg(tr, 14) // Adjust the period as needed
// Define coloring condition
color = if tr < atr
color.blue
else
color.maroon
// Plot the candles with coloring
plotcandle(close, high, low, open, color=color, wickcolor=color)
Using
barcolor()is better than trying to useplotcandle()for coloring candles. Also, ternary conditional operators (?:) are more efficient for your color designation. Try the following: