Be warned this is a highly opinionated post.
I propose a much simpler and realistic sample algorithm.
Some of the changes:
- Remove the notional concept which I found confusing and unnecessary
- Remove leverage. The idea that I can buy more than I can afford without being explicit about it confused me more than I'd like to admit
- Remove shorting. Shorting is complex and should only be introduced later
- Leverage and Shorting add more risk management concepts that should be left out of an introductory algorithm
- Change from wheighted moving average to simple price average
- Descriptive variable names
- More realistic initial cash amount