Hello David,
I fiddled with your code a bit...see the attached backtest. I opted to use the batch transform, with a 100-day window length. This way, it is straightforward to postpone trading until all of the moving averages can be computed (there is no "warm-up" for the built-in moving average when backtesting). I also added notional limits, in the same fashion as some of the examples on the help page. You have to constrain the algorithm in some way, or it can borrow unlimited amounts of money.
I also played around with your trading logic:
if price/mvg20>1 and mvg50/mvg20<1 and notional<context.max_notional:
order(context.stocks[0],100)
if price/mvg20>1 and mvg50/mvg20>1 and mvg50/mvg100<1 and notional>context.min_notional:
order(context.stocks[0],-100)
Grant