Hi.

Sorry for not writing anything last days, i´ve been kind of busy lately...

Coming back to the point discussed here, i must say i haven´t been able to make LinearRegSlope work properly in objective function. Something strange happen with this function as far as i´ve tested.

I am using polyfit instead, but i think something is not working or maybe i am not getting the results i was expecting.

Let´s take this piece of code:

Code:
static int criteria = 6;
static int minTrade = 0;

var objective()
{
    if(NumWinTotal+NumLossTotal <= minTrade) {     
        return 0;
    }
    else { 
        switch(criteria){
            case 0: //PRR
                var wFactor = 1./sqrt(1.+NumWinTotal); 
                var lFactor = 1./sqrt(1.+NumLossTotal);
                var win = WinTotal, loss = LossTotal;
               
                if(NumWinTotal > 2) win -= (NumWinTotal-2)*WinMaxTotal/NumWinTotal;
                if(NumLossTotal > 2) loss -= (NumLossTotal-2)*LossMaxTotal/NumLossTotal;
                return (1.-wFactor)/(1.+lFactor)*(1.+win)/(1.+loss);
            case 1: //PF
                return WinTotal/max(1.,LossTotal);
            case 2: //WinRate
                return (var) NumWinTotal/max(1.,NumWinTotal+NumLossTotal);
            case 3: //CAR
                return WinTotal-LossTotal;
            case 4: //Calmar
                return (WinTotal-LossTotal)/max(1.,DrawDownMax);
            case 5: //Sharpe
                return ReturnMean/ReturnStdDev;
            case 6: //K-Ratio
                var coeff[2];
                LookBack = Bar-StartBar;
                polyfit(coeff,ResultsDaily,Bar-StartBar,1,1);
                return coeff[1]*R2;
                // LookBack = 0;
                // return LinearRegSlope(ResultsDaily, Day)*R2;
        }
    }
}

function run()
{
	set(LOGFILE+PARAMETERS);
	BarPeriod = 4*60;
	LookBack = 500;
	StartDate = 2005;
	EndDate = 2015;
	
    asset("EUR/USD");

	vars Price = series(price());
	vars Filtered = series(BandPass(Price,optimize(30,20,40),0.5));
	vars Signal = series(FisherN(Filtered,500));
	var Threshold = optimize(1,0.5,1.5,0.1);

	Stop = optimize(4,2,10) * ATR(100);
	Trail = 4*ATR(100);

	if(crossUnder(Signal,-Threshold))
		enterLong(); 
	else if(crossOver(Signal,Threshold))
		enterShort();
    
	plot("Filtered",Filtered,NEW,BLUE);
	plot("Signal",Signal,NEW,RED);
	plot("Threshold1",1,0,BLACK);
	plot("Threshold2",-1,0,BLACK);
	PlotWidth = 1024;
	PlotHeight1 = 400;
}



Optimizing this system with almost any criteria produces an annual return ranging from 80% to 100%. However with K-Ratio it barely achieves an 60%.

Not sure if K-Ratio isn´t as good as i thought or if i´ve implemented it wrongly (most probably). The manual says something about polyfit having a cap of 1000 in TimePeriod parameter, so maybe here is the issue. I am also setting lookback to the whole number of bars in the simulation as this seems to work better.

This is everything i´ve figured out. Any suggestion or advice will be welcomed.