1

I created a script to color the candles displayed, with a different color depending on a condition, and to plot 2 MA's, but the candles show that color coded condition, only when I either hover over the MA's, or when I select the indicator at the top left panel.

this is the code

//@version=5
indicator("Custom Candle Colors with Moving Averages", overlay=true)

// Moving Averages
ma10 = ta.sma(close, 10)
ma30 = ta.sma(close, 30)

// Conditions
condition1 = close > open and close > ma10 and ma10 > ma30
condition2 = close > open and close < ma10 and ma10 > ma30 and close > ma30
condition3 = close < open and close > ma10 and ma10 > ma30
condition4 = close < open and close < ma10 and ma10 > ma30 and close > ma30

// Define Colors
lightGreen = color.new(#a8fd6f, 0)
mediumGreen = color.new(#53be56, 0)
Red1 = color.new(#f1cb4d, 0)
Red2 = color.new(#f7b272, 0)

// Set Candle Colors
candlecolor = close > open ? (condition1 ? lightGreen : (condition2 ? mediumGreen : na)) : (condition3 ? Red1 : (condition4 ? Red2 :na))

// Plot Candles
plotcandle(open, high, low, close, color=candlecolor)

// Plot Moving Averages
plot(ma10, color=color.blue, linewidth=1, title="MA10")
plot(ma30, color=color.orange, linewidth=1, title="MA30")

I tried to only leave the plotcandle instruction, but it is the same.

Rafa
  • 13
  • 2

1 Answers1

1

You need to bring the indicator to the front using the visual order. See screen shot below

Visual Order

smashapalooza
  • 932
  • 2
  • 2
  • 12