debug the Linear Regression Slope
Creation Date: 11/25/2011 9:43 PM

#1
I wrote a program. Entry at the next bar when both lrs10 and lrs20 are greater than 0. Exit at the next bar when either lrs10 or lrs20 is zero. It should be simple. But the error message made me confused. Since my operating system is Chinese, the error message is not English. It means "runtime error: not reference the object to the instance in wealthlab.strategies.mystratey.execute()". Here is the code. Could you please help? Thanks.
CODE:

BTW, I learned from the codes what is generated from rule.

#### Eugene

#2
There's no need to debug Linear Regression Slope, the error doesn't have anything to do with it.

LastPosition does not exist yet. You lost the entire IsLastPositionActive block somehow. It appears in the default Strategy template.

CODE:

#3
Thanks so much. Eugene, how many years have you spent on WLD/WLP? I am wondering how long it takes for me to reach your level. :)

#### Panache

#4
LinearRegSlope doesn't give the same result as calculating the slope between the beginning and ending points of the values from LinearRegLine.

CODE:

I get a very similar value if I substitute

CODE:

This becomes particularly relevant if you try to calculate the LinearRegSlope with a period equal to 1, which generates "NaN".

#### Eugene

#5
Is this question different from a similar thread you raised before?

LinearRegLine

#6

CODE:

#### Panache

#7
I understand what is happening, but I thought I'd give others a head up, that they need to add 1 to the period in LinearRegSlope to get the right value. The WIKI for LinearRegSlope says, "It looks at the prices for the number of specified periods and finds a straight line which best fits all the prices." which I interpreted as being the same as LinearReg, " LinearReg gathers the prices for the number of specified periods and finds a straight line which best fits all the prices".

#### Cone

#8
Right, but the first bar in "period" is not bar - period, rather it's bar - (period - 1), or, bar - period + 1.

Example:
Period = 10, and current bar = 1490. What's the first bar in the 10-bar period?

1490 - 10 = 1480. Counting bars from 1480 to 1490, inclusive, you'll get 11 bars. The first bar in the 10-bar period is 1481. Does that make it clear?