I don't know if this can help you ... it is just a little script to color the background behind ema's and when the candle close the background change. It works without the need to reload the graph. Guido
//@version=6
indicator(title="Background color behind EMA", shorttitle="Background color behind EMA", overlay=true)
showBackground = input(false, title="BG Buy-Sell", group="Background", inline="toggles")
length01 = input.int(1, minval=1, title="EMA 1") offsetV01 = input.float(defval = 0, minval=-10, maxval = 10, step = 0.01, title="EMA 1 Offset ▲▼") offsetH01 = input.int(defval=-1, minval=-500, maxval=500, step = 1, title="EMA 1 Offset ◄ ►") source01 = input(low, title="Sorgente EMA 1")
length02 = input.int(2, minval=1, title="EMA 2") offsetV02 = input.float(defval = 0, minval=-10, maxval = 10, step = 0.01, title="EMA 2 Offset ▲▼") offsetH02 = input.int(defval=1, minval=-500, maxval=500, step = 1, title="EMA 2 Offset ◄ ►") source02 = input(low, title="Sorgente EMA 2")
ema_to_plot_01 = ta.ema(source01,length01) ema_to_plot_02 = ta.ema(source02,length02)
buySignal = ema_to_plot_01 > ema_to_plot_02 sellSignal = ema_to_plot_01 < ema_to_plot_02
bgcolor(buySignal and showBackground ? color.new(color.green, 50) : na, offset = -1) bgcolor(sellSignal and showBackground ? color.new(color.red, 50) : na, offset = -1)
plot(ta.ema(source01, length01), title="EMA 1", color=color.red, offset=offsetH01, linewidth=1) plot(ta.ema(source02, length02), title="EMA 2", color=color.blue, offset=offsetH02, linewidth=1)