How can I put a trend signal at top right corner in tradingview chart when condition is met?

23 Views Asked by At

I have this macd code and I would like to add some trend signal when the condition is met. TREND UP=when currMacd value>signal value TREND DOWN=when currMacd value<signal value

Much appreciated if someone could help. Thank you so much.


//@version=4
//@author=LucemAnb
study(title="MT4 MACD ⛏", overlay=false)

src = input(title="Source", type=input.source, defval=close)
fastMA = input(title="Fast moving average", type = input.integer, defval = 12, minval = 7)
slowMA = input(title="Slow moving average", type = input.integer, defval = 26, minval = 7)
signalLength = input(9, "Signal Length", minval=1)

[currMacd,_,_] = macd(close[0], fastMA, slowMA, 9)
[prevMacd,_,_] = macd(close[1], fastMA, slowMA, 9)

signal = sma(currMacd, signalLength)
plotColor = currMacd > 0 ? currMacd > prevMacd ? color.lime : color.green : currMacd < prevMacd ? color.maroon : color.red
plot(currMacd, style = plot.style_columns, transp=20, color = plotColor, linewidth = 3, title="Macd Bars")
> plot(signal, color=color.white, transp=0, title="Macd Signal"

0

There are 0 best solutions below