See the code and backtest below for my take on implementing a simple trend following strategy inspired by Andreas Clenow's "Stocks on the Move".

The implementation uses a slope as trend indicator and rebalances the portfolio based on the ranked table of these slopes. 

Any comments are appreciated, particular regarding the following problems:

  1. The strategy doesn't make any trades during the backtest period, which might be connected to problem 2
  2. The ATR which is used as a volatility indicator to calculate the position size often is 0. How can I make sure that sufficient data is available from the get go?
  3. The size of the universe is 1 in the beginning and then 55, which is far off the intended universe size of 22.
  4.  ...
 

Author