Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Swing Trading Algorithm

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.

1 response

Josh,

I changed the algo to use "order_target_percent". It comes in handy especially if you're only buying or selling 1 security. To me it makes more sense to order towards a target percentage: 0%, 100%, -100% and even 200%(2) or -200%(-2) if you'd like to use leverage.

From what I've read, strategies that hold overnight positions will not ever get more than 2X margin for your broker. Day traders can get 4X but you're never going to be allowed to have -25 million cash in the account (week of oct. 20th)