In my script, I am trying to plot 50 EMA and if the price crosses above (first occurrence in a swing), I need to plot a shape. I am also looking to plot a shape above candle if current volume is higher than previous 20 candles. In both case, I need to show them above the candle.
Here is my script:
//@version=6
strategy("Test Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Inputs for EMA
ema_30 = ta.ema(close, 50)
// Individual Conditions
price_above_30ema = close > ema_30
// First Occurrence of price crossing 30EMA
first_cross_above_30ema= price_above_30ema and not price_above_30ema[1]
// Plot EMA
plot(ema_30, color=color.new(color.green, 0), linewidth=2)
//Plot price crossing 30 EMA - first occurance
plotshape(first_cross_above_30ema, location=location.abovebar, color=color.purple, style=shape.circle, size=size.small)
volume_avg = ta.sma(volume, 20) // 20-period average volume
above_avg_volume = volume > volume_avg
// Plot shape for above-average volume
plotshape(above_avg_volume, location=location.abovebar, color=color.orange, style=shape.diamond, size=size.small)
The problem I am facing here is, if both condition matches for a candle (Price crossed EMA and vaolume is higher than its avg), both the shapes are printing at the same spot and its hard to find due to the overlap. Looking at some of the tradingview documentation, I found a offset option but that seems not work in my case.
A sample candle which satisfies both the conditions:
How I need to show :
Try with text, and a \n
(newline)
something like this:
plotshape(first_cross_above_30ema, location=location.abovebar, color=color(na), textcolor=color.purple , text = "⏺\n")