Seeking Help for R2 indicator and Backtest stoploss


Would greatly appreciate some help - trying to code Andrea Clenow's popular momentum indicator. Optuma has LRINT() which I annualised (LRINT()*25). But I then need to calculate R2 to see determine the strength of the correlation. I was thinking of using the intercept function but how do I achieve - "Explained Variation / Total Variation".


The second question is I am running a re balancing back-test - how can I add a stop loss to test this. It appears stop losses are only available for signal back-testing. PS on my backtest I received a different result by using ROC() 20 days v ROC () 1 month. Is this normal?


thanks very much guys Mandeep