Many technical indicators such as the MACD for example, have a “signal line”. Traditionally a buy or sell signal is generated when the signal line crosses over or under the technical indicator.
The CROSSOVER function helps you one series has crossed over another. For example, we can find the exact point in time when one moving average crossed over another by using the CROSSOVER function:
SET MA1 = SMA(CLOSE, 28)
SET MA2 = SMA(CLOSE, 14)
Set BUY = CROSSOVER(MA1, MA2)
Set SELL = CROSSOVER(MA2, MA1)
//NOTE: If you want to plot the MA and the signals in the chart, include the following code.
plot(buy, buy, green, main)
plot(sell, sell, red, main)