R^2 of returns in the custom backtest procedure

I’d like to be able to select the r squared of returns as a metric for qualifying optimisations. Has anyone done any coding in this area?

You can take the code from the manual
http://www.amibroker.com/guide/a_custommetrics.html
or this code
http://www.amibroker.com/kb/2016/01/20/number-of-stopped-out-trades-as-a-custom-metric/

and modify it to calculate whatever statistic you need.