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 |

Moving linear regression. Rate this Topic:
Previous Topic · Next Topic Watch this topic · Print this topic ·
MDiep
Posted : Wednesday, April 19, 2006 8:38:16 PM
Registered User
Joined: 12/30/2004
Posts: 33
I tried to use the moving linear regression indicator in TC 2005 and tried to get information about its use,its parameters etc, but could not find anything, either in help or the manual. Could you direct me to a write-up on this indicator or otherwise enlighten me about its use?
TIA, Maurice
Doug_H
Posted : Wednesday, April 19, 2006 8:48:06 PM


Worden Trainer

Joined: 10/1/2004
Posts: 4,308
The moving linear regression simply plots the end point of the linear regression line over time (or any point on the line you choose to plot...the end point is the default). Here is the explanation from the OnLine Help File:


Moving Linear Regression
This indicator plots the path of the endpoint of a linear regression line back through the chart. The example below shows a 21 period Linear Regression and a 21 period Moving Linear Regression. You'll notice that the end of the Moving Regression (red) coincides with the endpoint of the Regression line (white). The Moving Linear Regression doesn't actually display the regression line itself, but in the graphic examples here it's displayed for illustrative purposes.

To plot a Moving Linear Regression line, click Chart Template | Add Indicator | Moving Linear Regression.

Period - length of the linear regression line used in the moving plot.

Extension - allows you to plot a moving regression line based on a linear regression line plotted with an extension. Example A shows a 21 period linear regression line (white) plotted with an 11 bar extension (magenta). The moving regression (red) has an extension of 11 bars as well and you can see where it's plotting relative to the regression line.

Point to Plot - you can choose which point on the linear regression line is used in the Moving Regression. You may want to plot path of the endpoint of the regression line (which is the default) or you may want to plot a different point along the regression line. Example B shows a 21 period moving regression (red) with a Point to Plot of 11. The gray line illustrates that the moving regression is drawn based on the 11th point on the line (in this case the middle).

Width - Setting a Width value will plot upper and lower channels around the Linear Regression line. The channel width is the average of the absolute differences between the parent value minus the average of the parent values up until that point calculated from the oldest to newest values in the Linear Regression Period. The width value is in tenths, so a value of 20 will result in a width equal to twice the result of the channel width calculation.

As to how best to use or interpret this indicator, that's really out of the realm of what we're able to cover in the Ask a Trainer forum. However, it's a great question for other TeleChart users who are familiar with moving linear regression, so I'll move this topic to the Stock and Market Talk forum, where you will likely receive input from at least several others out there.



- Doug
Teaching Online!
MDiep
Posted : Thursday, April 20, 2006 2:26:17 PM
Registered User
Joined: 12/30/2004
Posts: 33
Hi Doug,
Thanks for the info. I finally found it in the help file, was looking for moving linear regression! It seems like a versatile indicator. I'll play with it. Is there a formula or an expression for the channel width calculation? I'd be interested.
Thanks again, Maurice
Bruce_L
Posted : Thursday, April 20, 2006 2:58:28 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
MDiep,
You may wish to review the following:

Linear regression channel calculations
Using Linear Regression vs Classical Peaks/Valleys for Divergence Analysis

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
AlanK
Posted : Friday, April 21, 2006 9:11:23 AM
Registered User
Joined: 10/7/2004
Posts: 17
I use the interaction of 2 moving linear regression lines as a trend indicator. I would like to include my moving LR's in a Custom Cumulative Indicator that will track the occurrences of my lines crossing. Can you please help me with this?
Thanks.
Craig_S
Posted : Friday, April 21, 2006 10:24:46 AM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
What would you like the CumInd to do?

What will be the up condition?
Down condition?
What value should it move up or down?

Give me a litte bit more info and we should have no trouble putting this together.

- Craig
Here to Help!
Doug_H
Posted : Friday, April 21, 2006 10:27:56 AM


Worden Trainer

Joined: 10/1/2004
Posts: 4,308
It almost sounds like you meant to say Custom Percent True indicator. This type of indicator (if it could be written for your LR lines) would give an indication each time the lines crossed. Is that what you meant?

- Doug
Teaching Online!
AlanK
Posted : Friday, April 21, 2006 12:29:49 PM
Registered User
Joined: 10/7/2004
Posts: 17
Hey,

Thanks for the reply guys; much appreciated.
I do not know enough about the terms you guys use, and am at a total loss when it comes to deciding if I need "Percent True" or "Custom Cumulative". So, I'm very pleased to be able to rely on you for help.

I am attempting to create an indicator that will give an indication each time my lines cross (as Doug has noted). When they cross in a positive direction I look to go long and on the negative signal go short. Ultimately, I'd like to be alerted when the indicator triggers, but, I would at least like to be able to back test my methodology. My actual strategy (the parameters of my moving LR's) is something that I'd like to keep to myself for the time being if you don't mind.

I am available at (phone number removed by moderator) if you'd like to discuss this directly.

Thanks.
Craig_S
Posted : Friday, April 21, 2006 1:26:56 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
Take your PCF for the crossing and use it with this technique:

Visually Backtesting Specific Symbols

- Craig
Here to Help!
AlanK
Posted : Friday, April 21, 2006 1:38:36 PM
Registered User
Joined: 10/7/2004
Posts: 17
I don't have a PCF for the crossing. I just have the 2 lines on my chart and watch for them to cross.
Bruce_L
Posted : Friday, April 21, 2006 2:12:23 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
AlanK,
Explanations of how to create Linear Regression Personal Criteria Formulas are contained in the topics referenced in my Thursday, April 20, 2006 2:58:28 PM post. Your specific Linear Regression settings are required to write a formula.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
bustermu
Posted : Friday, April 21, 2006 3:56:42 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
Perhaps the most important property one needs to know about a moving linear regression (Linear Regression Moving Average (LRMA)) is that it is a Zero-Lag Moving Average.

Consider plotting LRMA5-LRMA10 on C as a Custom Indicator. Interpret it somewhat as you would an Exponential MACD Histogram. I always plot it along with the probability that it will increase tomorrow. I have never shown it to anyone who did not prefer it to the usual MACD Histogram. (I may use LRMA5-LRMA7, it is not available to me at the moment.)

The Indicator is used to determine changes in trend, but not for determining trends. This is because of the LRMA Zero-Lag property. The LRMA5-LRMA10 output is zero for a straight line input of sufficient length regardless of the slope of the line. Therefore, it cannot detect straight line trends as an Exponential MACD Line does.

I should reveal that I have used other Zero-Lag MA's for exactly the same purpose that I prefer to the LRMA's. Not that what I prefer should matter to anyone.

Thanks,
Jim Murphy
diceman
Posted : Friday, April 21, 2006 4:52:37 PM
Registered User
Joined: 1/28/2005
Posts: 6,049
bustermu

Isnt the lag of the LRMA related to its length??

Thanks

bustermu
Posted : Friday, April 21, 2006 5:41:13 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (diceman)
bustermu

Isnt the lag of the LRMA related to its length??

Thanks



No. The lag of an LRMA is zero regardless of its period.

Suppose the input to an LRMA is $10 for a long period of time and then the price increases $1 per day from then on. An LRMA of period P will sit right on the increasing line after it has received P-1 of the increasing inputs. The larger the period of the LRMA, the longer it takes to sit on the increasing line, but it will always get there since it has Zero Lag.

An SMA of period P will hang off the increasing line by $(P-1)/2 forever after it has received P-1 of the increasing inputs as its lag is (P-1)/2.

An EMA of period P will approach hanging off the increasing line by $(P-1)/2 as its lag is also (P-1)/2.

You should now see why an Exponential MACD Line can detect straight line trends but LRMA5-LRMA10 cannot.

Thanks,
Jim Murphy
diceman
Posted : Saturday, April 22, 2006 9:18:09 AM
Registered User
Joined: 1/28/2005
Posts: 6,049
Thanks bustermu.

A very nice idea. (using a LRMA oscillator).

I did not realize lag was zero for all lengths.
This makes LRMA my new favirote indicator to look into.

This also suggests that something like Bollinger Bands could be improved by using
LRMA as the center line.
( to be honest I never understood the concept of mixing the "accuracy" of STD with the
lag of a simple moving average but maybe nothing in the stock market can be veiwed
as accurate.)

Fast and slow LRMA seem to be excellent indicators when the market is in the
"cycle mode".


Perhaps the trend following capabilities of LRMA can be impoved by using some
type of offset:

fast LRMA with (slow LRMA * .98) for example.

or by using

fast LRMA of Highs or Close with slow LRMA of lows.

Thanks
S2
Posted : Saturday, April 22, 2006 12:47:16 PM
Registered User
Joined: 4/6/2005
Posts: 239
Bustermu,

I'm intrigued by your idea of plotting the LRMA as a custom indicator. However, I am not having any success in accomplishing this and the Telechart Help for this isn't.

Please, would you be more explicit in setting up this custom indicator?

Thanks

S2
diceman
Posted : Saturday, April 22, 2006 1:10:00 PM
Registered User
Joined: 1/28/2005
Posts: 6,049
S2

Check my post in the ask a trainer section
today for some LRMA PCFs.

Thanks
Bruce_L
Posted : Saturday, April 22, 2006 1:11:07 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
S2,
You may wish to review the second topic referenced in my Thursday, April 20, 2006 2:58:28 PM post as it explains a method to generate Linear Regressions as formulas in TeleChart. The following could be simplified a bit, but I've left it in its current form so it is easier to see how it was created based on the referenced topic:

LRMA5-LRMA10 on C:

AVGC5 + 2 * (2 * C + C1 - C3 - 2 * C4) / 10 - (AVGC10 + 4.5 * (4.5 * C + 3.5 * C1 + 2.5 * C2 + 1.5 * C3 + .5 * C4 - .5 * C5 - 1.5 * C6 - 2.5 * C7 - 3.5 * C8 - 4.5 * C9) / 82.5)

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
S2
Posted : Saturday, April 22, 2006 3:33:18 PM
Registered User
Joined: 4/6/2005
Posts: 239
Thanks Bruce,

I will give it a try and see how it works.

A question for you, what do the "magic numbers" represent? divisors 10 & 82.5. The same can be said for the 1.5, 2.5, 3.5 & 4.5 instances.

In programming we were always taught to variablize "magic numbers" so we would know what they refered to. I know the PCF "language" does not allow variables, unfortunately. But, without understanding what the "magic numbers" mean you are simply giving us fish, not teaching us to fish for ourselves.

If I knew what the numbers refered to I could modify the formula to try Bustermu's second settings LMRA5 - LMRA7 with out having to trouble you for it.

I will take a look at the links you provided in your first post in this thread. Also, FYI, the times on the post are shown in local time; your post on my end show an 11:58:28 time stamp (west coast time).

Thanks again for your assistance.

S2
Craig_S
Posted : Saturday, April 22, 2006 4:39:08 PM


Worden Trainer

Joined: 10/1/2004
Posts: 18,819
S2

That is all explained in the links Bruce provided the original poster at the top of this thread. Scroll up and check them out.

- Craig
Here to Help!
bustermu
Posted : Saturday, April 22, 2006 9:14:32 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (bustermu)
I should reveal that I have used other Zero-Lag MA's for exactly the same purpose that I prefer to the LRMA's. Not that what I prefer should matter to anyone.


There seems to be some interest in the Zero-Lag LRMA MACD. It seems only proper that I reveal my preference for the Zero-Lag DEMA MACD described in:

Setting up a DEMA MACD

Again, not that what I prefer should matter to anyone.

All Zero-Lag MACD's are for the purpose of signaling trend changes. They are not capable of identifying trends and I suggest they not be modified to give them that capability.

Thanks,
Jim Murphy
diceman
Posted : Sunday, April 23, 2006 9:01:27 AM
Registered User
Joined: 1/28/2005
Posts: 6,049
bustermu

Is it accurate to call DEMA MACD Zero-lag?

I would think low-lag would be more appropriate.

I would also believe "fixed" DEMA parameters would approach a lag of zero at
specific dominate cycle frequencies and have larger lag at others.

Also, due to the nature of the DEMA calculation process I would assume smaller
value period lengths would be more useful/accurate?
Lets say periods of 30 or less?

Thanks
bustermu
Posted : Sunday, April 23, 2006 10:51:49 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (diceman)
Is it accurate to call DEMA MACD Zero-lag?

I would think low-lag would be more appropriate.

I would also believe "fixed" DEMA parameters would approach a lag of zero at specific dominate cycle frequencies and have larger lag at others.


diceman.

Look at it this way. It is not anyone's fault that DEMA's are Zero-Lag MA's, it is just a fact. You seem to be introducing your own concept of "lag". That is alright, but you need to give it a different name, e.g., "diceman's lag". That way we will know you are talking about something different than the usual concept. You may have Lag mixed up with Phase Delay? The usual concept of Lag is given in:

Lag Efficient Moving Average

QUOTE (diceman)
Also, due to the nature of the DEMA calculation process I would assume smaller value period lengths would be more useful/accurate?
Lets say periods of 30 or less?


I do not know where you are getting your information. This is a quote from my post in the thread referenced on DEMA MACD:

"The PCF I use is:

2*(XAVGC5-XAVGC10)-(XAVG(XAVGC5,5)-XAVG(XAVGC10,10))"

Thanks,
Jim Murphy
diceman
Posted : Sunday, April 23, 2006 3:54:54 PM
Registered User
Joined: 1/28/2005
Posts: 6,049
bustermu

Realize that I am not arguing with you and am not trying to create my own version
of mathematics. I am simply trying to learn.

I put a line in a spreadsheet that started with a value of 1 and increased by a value of
1.

I applied a 10 period simple moving average to it and subtracted the moving average.
The value was 4.5.

Matching the equation: SMAV lag=(P-1)/2

As I understand it this is what you (and everyone else who knows this) are calling lag.

I thought if we changed direction in the line (started subtracting 1) the line would peak
then the moving average would peak. The difference in peaks I've heard called "phase delay",
"phase shift" and "phase lag" My understanding was the time from the input data peak
to the SMAV peak would be approx. 4.5 bars.

Therefore I was under the assumption that Lag and Phase Delay were the same or
at least directly related.

Your comment:

Quote:"You may have Lag mixed up with Phase Delay?"

Seems to imply that they are unrelated or less related then I thought.

Thanks
bustermu
Posted : Monday, April 24, 2006 11:24:52 PM
Registered User
Joined: 1/1/2005
Posts: 2,645
diceman,

If the input is a sinusoid, then the distance between peaks you describe is the phase delay at the frequency of the input. Phase delay is generally frequency dependent. If you search Google for:

INTRODUCTION TO DIGITAL FILTERS

you will find a free on-line book by Julius O. Smith III.

In TA we are interested in tracking filters. Julius is interested in audio and music where tracking filters, in the sense that we use them, are of no interest. Lag is not their problem.

Thanks,
Jim Murphy
diceman
Posted : Tuesday, April 25, 2006 12:03:34 AM
Registered User
Joined: 1/28/2005
Posts: 6,049
bustermu

My original questions stem from the work of John Ehlers.

He seems to feel Kalman filters are the best filters.(for zero lag smoothing)
Since he knows both the math involved and stock trading.
I think he has adapted them to be more stock friendly.

He also feels they are too much for the average trader to deal with.

He calls other filtering techniques "Sub-optimal" because they are not true Kalman.
( I assumed he meant closer to zero lag but not quite there)


Quote;"If the input is a sinusoid, then the distance between peaks you describe is the phase delay"

If I am understanding you correctly:

(This is in my English and may not be correct)

We call the delay in a moving average "lag" as long as the trend is rising or falling in one direction.

As soon as there is a cycle or turning point that lag contributes to or creates phase delay.


Thanks for the tip on the digital filters.

MDiep
Posted : Wednesday, April 26, 2006 2:32:17 AM
Registered User
Joined: 12/30/2004
Posts: 33
Hi everybody,I really appreciate all the feedback, but
I am thoroughly lost. So how do I write an expression to create a histogram of two moving linear regression lines to find out when they are crossing.
Also I was not able to add a MA to a single moving regression line. Why not?
I sure like to find out.
TIA, Maurice.

diceman
Posted : Wednesday, April 26, 2006 7:56:19 AM
Registered User
Joined: 1/28/2005
Posts: 6,049
MDiep

The Bruce L. post from April 22 shows the

LRMA histogram.



Were you looking for other lengths?


Thanks
bustermu
Posted : Thursday, April 27, 2006 2:14:44 AM
Registered User
Joined: 1/1/2005
Posts: 2,645
QUOTE (diceman)
Your comment:

Quote:"You may have Lag mixed up with Phase Delay?"

Seems to imply that they are unrelated or less related then I thought.


Your comment got me interested so I proved the following:

Theorem: The Lag and Phase Delay( w ), where w is frequency, of a Moving Average satisfy:

Lag = Phase Delay( 0 )

This seams as it should be after the fact. I have never seen it before, but I am sure that I am not the first to prove it.

Thanks,
Jim Murphy
MDiep
Posted : Thursday, April 27, 2006 2:29:37 PM
Registered User
Joined: 12/30/2004
Posts: 33
Thanks diceman,
I was not aware that it was a histogram.

Thanks, Maurice,
MDiep
Posted : Friday, April 28, 2006 3:34:17 PM
Registered User
Joined: 12/30/2004
Posts: 33
Diceman,
I copied the formula that Bruce supplied in his post of April 22, and it resulted in a single line, just as a non-histogram MACD, namely the difference between two LMRA's that I plotted on the price chart. Thanks again for pointing to that post. You also asked if I wanted different lengths. Indeed I like larger time periods and since I do not understand or know the basics of the LRMA formula, I am not able to change the parameters. Can you give me a hint, or direct me to the source?
And how do I get a histogram of the difference between the LRMA's? I applied a MA to it, but I don't know how to develop that into a histogram in TC 2005.
TIA,
Maurice
Doug_H
Posted : Friday, April 28, 2006 3:35:40 PM


Worden Trainer

Joined: 10/1/2004
Posts: 4,308
Custom indicators cannot be plotted as histograms in TeleChart.

- Doug
Teaching Online!
Bruce_L
Posted : Friday, April 28, 2006 3:48:07 PM


Worden Trainer

Joined: 10/7/2004
Posts: 65,138
MDiep,
You are correct when you say my Saturday, April 22, 2006 1:11:07 PM is not the formula for the LRMA MACD Histogram (which would be plotted as a line chart in any case). It is the formula for an LRMA based MACD(5,10) with no formula given for its Trigger Line or Histogram. There has been some discussion that adding a Zero-Lag Trigger Line to a Zero-Lag MACD is undesirable. I do not offer an opinion on its utility, but I will note that the Trigger would cross the MACD (the Histogram would cross zero at the same time) with much greater frequency than with a normal MACD.

My Thursday, April 20, 2006 2:58:28 PM post responding to your Thursday, April 20, 2006 2:26:17 PM question references topics explaining how to construct the Linear Regressions as Personal Criteria Formulas.

-Bruce
Personal Criteria Formulas
TC2000 Support Articles
diceman
Posted : Friday, April 28, 2006 4:46:03 PM
Registered User
Joined: 1/28/2005
Posts: 6,049
MDiep

As I understand it a histogram is a form of plotting (with above and below zero bars)
Anything that goes above and below zero can be plotted as a histogram. If the software
has that capability.

There is also the histogram as it refers to the "MACD HISTOGRAM" which is the
difference between 2 MAVs and then a trigger line is applied to that and the difference is the histogram.

I was thinking of the first situation when I called it a histogram.

In this case the periods are so short (5/10) that I don't think a trigger MAV is necessary.
It may help if using longer values.

The formula is for the difference between the 2 lines.

If you need to see the signals more clearly you can use two percent true indicators:

LRMA5-LRMA10>0=GREEN
LRMA5-LRMA10<0=RED

(you can have equations for other lengths)

put these is the same window and it will switch green/red as the indicator goes above
and below zero.

Thanks
MDiep
Posted : Tuesday, May 2, 2006 10:48:34 PM
Registered User
Joined: 12/30/2004
Posts: 33
Hi Diceman, Doug, Bruce and Craig, and everyone else.
I am very thankful for all the support and good advice that I received about moving linear regressions. I like the indicator and used it before and want to expand its usefullness to me.
This has given me a lot of possibilities to experiment.
Thanks again,
Maurice
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.