*This is a sample question. You have the option to put more information here.
You can copy-paste the code below into your VAI Script editor. The code below can also be found here.
This formula will also plot the trading signals into the VAI Chart
//Buy when MACD Line crossed up, otherwise sell
//set variables
set macd_line = MACD(13, 26, 9, EXPONENTIAL)
set macd_signal = MACDSIGNAL(13, 26, 9, EXPONENTIAL)
set hist = macd_line – macd_signal
//Buy condition
Set BuySignal = CROSSOVER(macd_line , macd_signal)
//Sell Condition
Set SellSignal = CROSSOVER(macd_signal, macd_line)
//Plot MACD
plot(macd_line, line, any, macd)
plot(macd_signal, line, any, macd)
plot(hist, bar, any, macd)
//Plot Buy and sell signals
Plot(BuySignal, Buy, Green, main)
Plot(SellSignal, Sell, Red, main)
@vanguardai hello, would it be possible for a command/script with conditions regarding MACD Histogram?
e.g.:
BUY if MACD Histogram is ascending (current bar is greater than previous bar) and vice versa for SELL
Yes, but it may show a buy signal everyday if the histrogram is increasing everyday but it is possible.
Set BuySignal = hist > ref(hist,1)
Set SellSignal = hist < ref(hist,1)
The ref function means reference to a past period, in this case 1 period in the past. so the system will check everyday if the histogram is higher or lower than the previous period and provide the appropriate signal.
@vanguardai thank you so much, its ok if its giving me signals everyday because its just a part of my system, confirming momentum movement.