I want to change the candlestick chart color based on the SuperTrend indicator. I did but there is a problem. The candlestick colors change only if I put my mouse on the SuperTrend line. I want these colors to stay all the time.
Here is my code:
//Supertrend
atrPeriod = 10
factor = 3
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
//Line Plots
LineColorUp = direction < 0 ? color.green : na
SuperTrendUpPlot = plot(supertrend, color = LineColorUp, linewidth = 2, title = "SuperTrendUpPlot")
LineColorDown = direction >= 0 ? color.red : na
SuperTrendDownPlot = plot(supertrend, color = LineColorDown, linewidth = 2, title = "SuperTrendDownPlot")
//fill
bodyMiddle = plot((open + close) / 2, display=display.none)
fillColor = direction < 0 ? color.green : color.red
fill(bodyMiddle ,SuperTrendUpPlot, color.new(fillColor, 90), fillgaps = false)
//Candle Color
candleColor = direction < 0 ? color.rgb(0, 255, 8) : color.rgb(255, 0, 0)
plotcandle(open, high, low, close, color = candleColor)
It is not a code issue here. You just need to use the visual order to bring the indicator to the front.