Error 17 missing argument

What's wrong with the below code? Thanks!

function OLS_Slope(p)
{
	d=p-Ref(p, -1);
	
	m=(Sum(d*d)-Sum(d)*Sum(p))/Sum(p*p)-Sum(p)*Sum(p);


return m;
}

slope=OLS_Slope(C);
Plot(slope, "slope", colorBlue, styleLine);

Sum takes TWO parameters, http://www.amibroker.com/f?sum - input array AND number of bars to calculate running sum on.
See also
http://www.amibroker.com/guide/h_understandafl.html

To calculate running sum over ALL elements you can use Cum http://www.amibroker.com/f?cum

1 Like