Ditto and I'll try to add some basics.
The closing of positions were not all complete before opening positions, so then starting with 10k the amount invested was 72k, quite a bit of margin. It is an example of the importance of partial fills on our radar that affects us all.
This mainly sets a context variable to wait for all closing orders to be done, then trade_stocks() has a clean slate. Logging shows some detail on any incomplete orders. There's still a bit of margin you might want to look into, just to understand it. Except for minute in the chart, click legend items to toggle them off, there are times when incomplete closing orders linger over 100 minutes into the day, although, due to smoothing, you'd need to zoom in to see the extent of any spikes; they are more visible during a run, or look thru the time stamps in logging output. So, fewer partials-overlap-unknowns here, can hopefully help. Return on amount invested was 95% due to margin, this increases that to 756%, holding the amount invested to 11.6k. Interesting strategy.