I have atarted a new topic as although about the same algo, it is a completely different issue:

I am trying to implement an exponential regression within an algo. In theory this is an indicator of momentum in a stock. 

The problem is I already implement this in a python algo and it correctly identifies positive momentum stocks for me.

When I have tried to implement it with almost identical(this may be the issue!) it identifies negative momentum stocks as positive.

I have tried to compare a mock up in a notebook (attached) to the backtest(also attached). It is clear that when it carries out what appears to be the same calcualtion in the algo it returns positive results(for slope and r value in particular) where it should be identifying them as negative values (and does in the notebook and in my python algo).

This of course leads the algo to be an extreme loss maker where it should be moderately profitable, as it is going long on stocks that are screaming shorts.

If anyone can help by pointing out where the error or amendment is required I would be appreciative.

Thanks

Mark