When we detect a moving average cross , be it of the golden or death variety - it is crucial to avoid a false positive and get the correct cross to ensure trading the movement profitably.
What I have found broken in the majority of public code posted online is the programmer has neglected to check the previous bars position. So their cross code is working in an assumption that if x < y it was a cross. This can give continual false positive and return a highly unprofitable strategy.
Realistically, when we look at a chart we do not make this calculation but rather if x1 < y1 and x2 > y2 wherex1 is the last bars close price and y1 is the last bars moving average. We look to see if it was under before, and over after. Thus calculating a cross correctly.
So for a Death Cross - we must detect if the slower moving average has risen above the faster. E.g if SlowMa1 < FastMa1 and SlowMa2 > FastMa2
Using two sample points we are able to see if the slower moving average of the previous bar SlowMa1 was below the faster MA and now in the next bar has risen above. Signalling a Death Cross, we can look to enter a short position.
The inverse of this can be applied to correctly detect a Golden Cross, and open a position for that.
For an indicator you can trigger an alert and append a log entry for the cross, to automate trading we can possibly work with the JavaScript libraries available in a trading bot environment like Gekko which works with popular crypto exchanges such as Poloniex and Bitfinnex.