This is a really basic Momentum Trending Trading strategy. The algorithm looks at a short-term (30 days) and long-term (90 days) moving averages of the S&P 500.
When the two moving averages intersect, the algorithm will either invest or sell out. It will then invest when the short term moving average is greater than the long-term moving average and sell when the long-term moving average is greater than the short-term moving average.
Below is the Pseudo-code of the algorithm:
IF (short-term moving average intersects long-term moving-average) THEN
IF(short-term moving average > long-term moving average) THEN
Invest in security
ENDIF
IF(short-term moving average < long-term moving average) THEN
Sell security
ENDIF
ENDIF
Also note that this algorithm trades a one-asset portfolio (the S&P 500), but can be easily modified to trade a dynamic or static multi-asset portfolio. Let me know if you need help on this conversion.