Reputation: 1
I have developed a traffic light indicator based on the 3/10 oscillator, designed to change the EMA color depending on its status in two higher time frames.
However, I am facing an issue I cannot resolve. The coloring works only for candles finalized when I open the chart. For those that develop afterward, the EMA does not display the correct color. It seems that something else is influencing the EMA. If I reload the tab, the coloring is correct again.
Below is the relevant part of the Pine Script:
var color stabileEMA_Farbe = na var color ema_farbe_vorherige_kerze = na
neueKerze = bar_index > bar_index[1]
if neueKerze ema_farbe_vorherige_kerze := gesamtAmpel // Speichert die Ampelfarbe der letzten Kerze
stabileEMA_Farbe := nz(ema_farbe_vorherige_kerze, ampel_orange) // Fallback: Orange
out = ta.ema(src, len)
plot(out, title="EMA", color=color.new(stabileEMA_Farbe, ema_transparency), linewidth=2)`
I tried to fix the issue by ensuring that the EMA color is determined based on the 3/10 oscillator rather than being influenced by the current candle. To achieve this, I stored the previous candle’s EMA color and applied it consistently, using a fallback color when necessary.
The expected result was that the EMA color would remain stable and correctly reflect the oscillator’s signals, regardless of newly forming candles. However, the issue persisted, where the EMA color appeared to change dynamically with the candle itself until the tab was reloaded.
[Chart before reload](https://i.sstatic.net/fz4qcRB6.png)
[Chart after reload](https://i.sstatic.net/cJxKxygY.png)
[Indicator](https://de.tradingview.com/script/acw6R9Yf/)
I’d appreciate any insights on resolving this. Thanks a lot!
Upvotes: 0
Views: 26