I recently have been transfering over my code from Quantopian.  I was hoping I could get some help.

1.  I am receiving a "Runtime Error: Algorithm took longer than 10 minutes on a single time loop. CurrentTimeStepElapsed: 10.0 minutes" when I try to run a backtest from Jan 1 2020 to October 30 2020.  It runs fine when I run the backtest for a few days.  Anyone have a fix for this?

2.  When I can get the backtest to function it is rather slow.  Are there any code optimization suggestions that can speed this algo up?

3. Would it be possible for me to also add in the "def Rebalance" a condition that not only must the stock gap up 10% from yesterdays close to todays open, but also that the opening gap up price be higher than any price in the last 40 days (basically longing a breakout).  In the tutorials it talks about a rolling window but I was wondering how I can have my "sortedSymbols" sort for >10% gap up AND higher than 40d high at the same time?  What would the "def Rebalance" code look like?