I've been researching the forums and am trying to find an example of a strategy I'm trying to build but haven't had any luck yet.
The parameters of the strategy are fairly simple:
1. Three tickers (MSFT, AAPL, SPY)
2. Use Moving Average (Close, SMA, 50) as the analysis tool to buy or short based on below conditions
3. In order for initial trade to start, the Price must cross above/below the SMA
1D:5M
either A or B can occur first:
A. If price is currently BELOW the SMA line, and then crosses ABOVE the SMA line, a BUY order is placed with total shares equaling (total investment capital of $1,000,000) / (Current Share Price). This position is held until B occurs, at which point the bought shares are sold (so the position is closed.
B. If price is currently ABOVE the SMA line, and then crosses BELOW the SMA line, a SHORT SALE order is placed with total shares equaling (total investment capital of $1,000,000) / (Current Share Price). This position is held until A occurs, at which point the shorted shares are ‘covered’ (so the position is closed.
A will always be followed by B, and vice versa (i.e.: as soon as one position is closed, the opposite position will be opened). It is crucial that the previous position be closed before the next position can be opened (i.e.: if a stock was bought, it must be sold before it is then shorted…….and if a stock was previously shorted, it must be covered before a buy order is made.
It's a very simple strategy but will show a few key parts in the algorithm:
- How to build an algorithm using multiple tickers
- How to build an algorithm that combines both buying and shorting
- Requiring a previous position to be closed before a new position is immediately opened thereafter on the same security.
If there's an existing available algorithm built, or if someone could take the time to show how this could be built, I'd very much appreciate it.
Thanks