Download software Tutorial videos
Subscription & data-feed pricing Class schedule


New account application Trading resources
Margin rates Stock & option commissions

Attention: Discussion forums are read-only for extended maintenance until further notice.
Welcome Guest, please sign in to participate in a discussion. Search | Active Topics |

Linear Regression Trendlines Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
Matman
Posted : Wednesday, April 29, 2009 4:07:30 PM
Registered User
Joined: 3/20/2005
Posts: 45
Hi,

In TeleChart you an clip back the data one bar at a time usng the [ key. When I do this my Linear Regression lines change as the data changes. In StockFinder my Linear Regression Trendlines do not change at all. Instead they move right of the chart as I press the [ key. Is there a setting to change this, or some RealCode way around this?

Thanks,

Dave
Bruce_L
Posted : Wednesday, April 29, 2009 4:34:27 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
It's possible, albeit far from pretty. I've created RealCode Linear Regression Channels that use a parent Indicator based on Price that has been trimmed by the Chart Start and End Dates. The fact that it uses the Chart Start and End Dates means it must be saved as a Chart instead of as an Indicator. You should be able to Open the attached Chart directly into a running copy of StockFinder.

Attachments:
LR_Channel_Scrolling.sfChart - 84 KB, downloaded 571 time(s).



-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Matman
Posted : Wednesday, April 29, 2009 5:50:13 PM
Registered User
Joined: 3/20/2005
Posts: 45
Bruce,

Thanks for the Prompt reply! Would this code work on Stochastics? If so, Is there anything that would need to be changed?

Thanks again,

Dave
Matman
Posted : Wednesday, April 29, 2009 6:30:11 PM
Registered User
Joined: 3/20/2005
Posts: 45
Sorry, Let's try this again.

My Linear Regression Lines are Child Indicators of various Stochastics. So would your code work on those lines?

Dave
Bruce_L
Posted : Thursday, April 30, 2009 8:43:38 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
There is nothing which technically prevents the Indicator from being used with an Indicator other than Price. I've replaced the file attached to my Wednesday, April 29, 2009 4:34:27 PM ET post with a Chart that contains Linear Regression Channels for both Price and the %K line of a Stochastic.

That iit is possible does not make it easy however. The current version of StockFinder does not have a way to save Child Indicators (although even if it did, the fact that we are referencing the Chart Start and End Dates would prevent us from saving the Indicator anyway).

If you Drag and Drop all four components from one Pane to another and select Overlay, the Indicator would still be based on Price even if you also right-clicked on each component and selected Scaling | Scale With | (Parent Indicator) to force it into the same Scale. You would need to right-click on the LR Parent Indicator and select Block Diagram and then left-click and Drag on the Date & Number Series input of the Trim by Dates Block and choose Link From Another Tool | (Parent Indicator) to get it to use the correct Parent.

Things become more complicated if you want to have more than one LR Channel and you need to copy and paste the LR Channel Components to create duplicates. Not only do you need to go into all three of the Block Diagram based components to make sure they have the right right parents, you also need to edit the RealCode of the LR Channel Indicator to change the '# LP = indicator.LRParent line to reference the correct LR Parent Indicator (since there will be more than one).

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Matman
Posted : Thursday, April 30, 2009 10:54:38 AM
Registered User
Joined: 3/20/2005
Posts: 45

Bruce,

Thank you, I'll play with this and see if I can get it to do what I want. Do you know if there are any plans for StockFinder to get Linear Regression Trendlines to behave like they do in TeleChart?

Dave

Bruce_L
Posted : Thursday, April 30, 2009 11:25:32 AM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
I do not know.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Matman
Posted : Thursday, April 30, 2009 12:57:09 PM
Registered User
Joined: 3/20/2005
Posts: 45

Hi Bruce,

The reason I have been asking is that I have written a RealCode indicator that gives me the angle of my Linear Regression Trendlines. This works well when used on Stochastics as the scale is 0 - 100. I use the LRT period as my X scale and the LRT value as the Y scale. The angle given remains constant throughout zoom levels and of course it changes when I change the charts from Daily to Min. I asked because I wanted to move back one bar at a time to do some visual backtesting. 
The only other question I have is this - Is the Linear Regression Trendline Period property exposed to RealCode?

If you are interested here is the code I wrote:

'***************************************
'* Gives the angle of LR Trendline     *
'***************************************

'# LRT = indicator.LinearRegressionTrendline

Dim Angle As Single
Dim Period As Integer
Period = 35
 
If LRT.Value = LRT.Value(1) Then
 Angle = 0
 Plot = Angle
Else If LRT.Value < LRT.Value(1) Then
 Angle = -90 - (System.Math.Atan(Period / (LRT.Value - LRT.Value(1))) * (180.0 / System.Math.PI))
 Plot = Angle
Else
 Angle = 90 - (System.Math.Atan(Period / (LRT.Value - LRT.Value(1))) * (180.0 / System.Math.PI))
 Plot = Angle
End If

Thanks for the help.

Dave

Bruce_L
Posted : Thursday, April 30, 2009 1:00:36 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
If you want to be able to use User Input to adjust the Period, try changing the following two lines:

Dim Period As Integer
Period = 35

To:

'# Period = UserInput.Integer = 35

Another thought that I think might eliminate the need for the Period Input entirely would be to Drag and Drop a Linear Regression Slope of Indicator for your first line instead of a Linear Regression Trendline Indicator.

'# LRS = indicator.LinearRegressionSlope
Dim Angle As Single
If LRS.Value = 0 Then
    Angle = 0
Else If LRS.Value < 0 Then
    Angle = -90 - (System.Math.Atan(1 / LRS.Value) * (180.0 / System.Math.PI))
Else
    Angle = 90 - (System.Math.Atan(1 / LRS.Value) * (180.0 / System.Math.PI))
End If
Plot = Angle

I haven't really tested it, but I think it should produce similar results to using your Indicator where the Period is set to the LR Period minus one.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Matman
Posted : Thursday, April 30, 2009 1:33:03 PM
Registered User
Joined: 3/20/2005
Posts: 45

Bruce,

Thank you, I'll give it a go and let you know how it works. I won't be able to get to it until later.
Thanks again.

Dave

Bruce_L
Posted : Thursday, April 30, 2009 1:36:58 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
You're welcome.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
Users browsing this topic
Guest-1

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.