Bullish MACD Crossover
The purpose of this indicator is to detect the crossover of the MACD oscillator lines. A bullish crossover happens when the MACD line crosses up through the signal line.
Open the Indicator Builder from the menu.
- Add a MACD operator in the top row.
- Click the MACD row, then click the plus symbol in the toolbar to add a new row above
- Set the new row to a Step function
- From the first selector in the MACD row, select Difference
- Add a new top row again, and set it to Dirac Delta
- Add another row and set that to Threshold
- Add a final row and set it to Buy
We use the Difference output from the MACD and pass that into a step function. The MACD difference line is the MACD line minus the signal line. When the Difference line crosses from minus to plus that is the same as the MACD line crossing up through the signal line.
The step function simply shows where the Difference line is above zero. As we’re only interested in the step itself, we can use a Dirac Delta which will create a positive or negative value at the step edges and will be zero everywhere else. The image below shows the output of Dirac Delta on the step function.
As we only want to detect bullish crossovers, we use the Threshold function to remove negative values from the Dirac Delta. This now gives us just the places where the MACD line is crossing up through the signal line.
To detect the bearish crossovers, where the MACD line moves down through the signal, we would just need to have added a Negate operator above the delta function.
Lastly, the Buy will create a buy signal whenever it’s input is true. This completes the logic. Now we can test the indicator on different symbols and timeframes. The chart above shows the bullish crossovers on Amazon stock (Weekly chart). As we can see, buying at the crossovers was successful 73% of the time, over this range, and delivered an average profit of 24.7%