Linear Regression Slope, LinearRegSlope
Author: tradercn
Creation Date: 11/25/2011 9:43 PM
profile picture

tradercn

#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:
Please log in to see this code.


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

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:
Please log in to see this code.
profile picture

tradercn

#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. :)
profile picture

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:
Please log in to see this code.


I get a very similar value if I substitute

CODE:
Please log in to see this code.


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

Eugene

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

LinearRegLine
profile picture

Cone

#6
Add this to the end of your example to compare:

CODE:
Please log in to see this code.
profile picture

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".
profile picture

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?

This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).