0

enter image description hereenter image description here

I am trying to build a BUY/SELL Indicator for TradingView by EMA.

Conditions for BUY Signal: The 9 EMA LINE (Green) is above the 18 EMA LINE (Red)

Conditions for SELL Signal: The 9 EMA LINE (Green) is below the 18 EMA LINE (Red)

When the above conditions are met it should give the respective BUY or SELL signal.

But, I am not being able to fill background & plotbarcolor for the correct BUY/SELL signal that meets all the conditions.

My codes:

//@version=5 indicator(title='EMA', overlay=true)

s9ema = ta.ema(close, 9) s18ema = ta.ema(close, 18)

longCond = ta.crossover(s9ema, s18ema) shortCond = ta.crossunder(s9ema, s18ema)

plotshape(series=longCond, title='BUY', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), text='BUY', size=size.small) plotshape(series=shortCond, title='SELL', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), text='SELL', size=size.small)

1 Answers1

0

you can use bgcolor to plot background color and barcolor to plot the color of bar. example below

    //@version=5 
indicator(title='EMA', overlay=true)

s9ema = ta.ema(close, 9) 
s18ema = ta.ema(close, 18)


plot(s9ema,color=color.green)
plot(s18ema,color=color.red)
longCond = ta.crossover(s9ema, s18ema) 
shortCond = ta.crossunder(s9ema, s18ema)

bgcolor(s9ema>s18ema?color.new(color.green,70):s9ema<s18ema?color.new(color.red,70):na)
barcolor(s9ema>s18ema?color.new(color.green,40):s9ema<s18ema?color.new(color.red,40):na)

plotshape(series=longCond, title='BUY', style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.white, 0), text='BUY', size=size.small) 
plotshape(series=shortCond, title='SELL', style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.white, 0), text='SELL', size=size.small)
Rohit Agarwal
  • 1,258
  • 1
  • 3
  • 9