How to calculate regression slope  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
robbob
Posts: 46
Joined: 26 Jan 2013
Has thanked: 2 times
Been thanked: 3 times

How to calculate regression slope

Postby robbob » 11 May 2013

It appears that a number of things have changed between 8.0 and 8.5 that have broken a number of my scripts. I'm in the process of trying to fix them and I am having issues calculating the slope of a regression line.

Previously there was a LinearRegSlope object, but this no longer exists. I'm attempt to use the LinearReg object, but I'm always getting 0 when accessing the linearReg.olrslope property.

I'm initialize the linearReg object in the Strategy's create() method as follows:
linearRegression = LinearReg(this).

in the StartCalc() method:
linearRegression.price = Bars.Close;
linearRegression.length = 15;

In the strategy's CalcBar method, I attempt to get the slope:
linearRegression.olrslope;

this however always returns 0.

thanks,
-Rob

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: How to calculate regression slope

Postby Henry MultiСharts » 13 May 2013

Hello Rob,

We will check that.

mips4pips
Posts: 10
Joined: 27 Nov 2012
Has thanked: 10 times
Been thanked: 2 times

Re: How to calculate regression slope  [SOLVED]

Postby mips4pips » 13 May 2013

Hi Rob,

I get good values for the slope in my strats. My code is like yours, with two exceptions:

- In Create() ---> linearRegression = new LinearReg(this);

- in CalcBar() ---> linearRegression.call();

Hope this helps. If this code is incorrect, I would really like to know about it.

Thanks,
mips4pips

robbob
Posts: 46
Joined: 26 Jan 2013
Has thanked: 2 times
Been thanked: 3 times

Re: How to calculate regression slope

Postby robbob » 13 May 2013

That did the trick.

Thanks!
-Rob


Return to “MultiCharts .NET”