Hi Tristan, glad you like it.
The algo here really is a code template. It shows a building block of some of the algorithms shared by Quantopian pros in the past. I use the inverse of the 21-day standard deviation for position sizing - intuitively, the more SPY jumps around, the fewer shares I hold. Other approaches, such as Average-True-Range (ATR) do a similar job. The trend filter then prevents the algorithm from increasing its position in SPY should the market be below the 200-day moving average.
I'll add more comments to future examples so they're easier to follow.