Swing trading is a trading strategy to profit from swings in the prices of assets. This strategy buys the asset when its price is a low of a cycle and sells at a high. In order to reduce the subjectivity of fundamental or technical analysis in this strategy, a trading rule is established to give buy and sell signals. In comparison to other strategies, swing trading is a hybrid between day trading and fundamental investing. A swing trader must create a system to buy and sell securities relatively quickly; however, the trader holds the asset for several days compared to seconds or minutes.
Profits from swing trading are generate from large movements in asset prices. However, a major risk of this strategy is sideways price movement because the trading rule can decipher a specific direction of price. As a result, swing trading in this type of market will bring lower than market returns.
This algorithm buys and sells an index fund tracking the S&P 500. Its trading rule uses the five and twenty day moving averages of the index fund to determine when to buy and sell. The stock is bought if the 5 day moving average is lagging behind a multiple of the 20 day moving average. The fund is sold if the 20 day moving average is ahead a multiple of the the 5 day moving average. The multiple is a parameter than can be changed depending on ones sentiment about the volatility of the market. A simple modification could be to tie this parameter to the value of a measure of market sentiment such as the VIX.