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

Hi everyone,
I am a student and this is one of my first times experimenting on Quantopian. I tried to do a basic moving average algorithm that makes trades based on the crossover of 17 and 40 days of Apple between 01/01/2011 and 12/31/2014. Can anyone help me with:

1) I tried to schedule the trades starting from 15 minutes after the market opens and 11 minutes before the market close; in order to be able to use the 25% of stock value margin and not to incur in the "Reg T End of Day Initial Margin", which requires 50% instead. However, I believe that there must be something wrong with the cash. How could I improve it?

2) Isn't there any way to add the MACD ratio into the picture? I want to reduce commissions for unnecessary trades.

Thanks in advance for the help,
Mattia

1 response

Hello Mattia,

For every scheduled action you don't wish to happen simultaneously you should use different functions, e.g. one function for opening positions and another for closing them. For recording rapidly changing variables like cash you shouldn't use function which is timed to run just once per day.

I added few functions to your original code. Now it has three separate functions with three separate timing schedules. One (open_positions) for opening positions 15 minutes after market opening, one (close_positions) for closing positions 11 minutes before market closing and one (record_variables) for running non stop recording portfolio cash.

For adding MACD into you algorithm you should check following link: https://www.quantopian.com/help#macd