Hi, Patrick. Thanks for sharing your algorithm.
AMD is a gift that keeps giving. For some perspective, a simple buy-and-hold of AMD during the same period nets 373% gains. But of course, your algorithm significantly reduces beta and volatility, and that cash that's freed up every time you sell can theoretically be used on other profitable low-volatility trades between AMD trades.
I tried swapping AMD out for MU and GOOG_L and the results were terrible. Do you use a different MACD periods tailored to the different stocks in your basket? If so, how do you determine those values? Or do you use entirely different strategies for each stock? I'm curious how you apply this outside of AMD. Do you have an out-of-sample success-rate with it? I'm curious how you approach this issue with statistical rigor.
What's the screening criteria for your basket of stocks? Is it something you could recreate through pipeline?
If you want to run the MACD check once every 30 minutes instead of minutely it won't affect the results too much and speeds up the backtester quite a bit, this is one way you can do that:
def handle_data(context, data):
if get_datetime().minute % 30 == 0: