explorer coding to find out r-squared period please help
#1
Posted 28 January 2010 - 05:52 PM
I tried to understand r-squared indicator which it can measure strenghtness of stock movement. The r-squared with correlate with confidence level, we can see on metastock help. I like to know how to explore period of security which is weak (r-squared=0.0001) or strong (r-squared=0.80).
Please help me.
Regards,
Ade
#2
Posted 28 January 2010 - 06:04 PM
Good luck,
--Johnathan
#3
Posted 29 January 2010 - 12:09 PM
JohnathanStein, on 29 January 2010 - 07:04 AM, said:
Good luck,
--Johnathan
Johnathan,
Do you mean we cannot use R-squared as one of trading tools? Please kindly explain to me.
Thank you
Ade
#4
Posted 29 January 2010 - 05:56 PM
in the most general case the r-squared (r^2) measures how well a model fits to reality. r^2=0 means no fitness at all and r^2=1 means perfect fitness.
Metastock help is a bit misleading when it comes to r^2 so I 'll try to explain it in simple terms. The r^2 of Metastock measures how well the closing price movement in a chart (the reality) resembles a straight line (the model). If you calculate the r^2 of say the last 20 bars of a stock in Metastock and you find that r^2 is 1 then this just means that the last 20 closing prices are moving in a perfect straight line (more precisely, they are moving in a perfect oblique line, not horizontal) and nothing more. As such, the r^2 does not offer an indication of trend strength in and of itself since the slope of the oblique line could be very small in absolute value.
Giorgos
#5
Posted 30 January 2010 - 12:12 PM
Siligard, on 30 January 2010 - 06:56 AM, said:
in the most general case the r-squared (r^2) measures how well a model fits to reality. r^2=0 means no fitness at all and r^2=1 means perfect fitness.
Metastock help is a bit misleading when it comes to r^2 so I 'll try to explain it in simple terms. The r^2 of Metastock measures how well the closing price movement in a chart (the reality) resembles a straight line (the model). If you calculate the r^2 of say the last 20 bars of a stock in Metastock and you find that r^2 is 1 then this just means that the last 20 closing prices are moving in a perfect straight line (more precisely, they are moving in a perfect oblique line, not horizontal) and nothing more. As such, the r^2 does not offer an indication of trend strength in and of itself since the slope of the oblique line could be very small in absolute value.
Giorgos
Dear Giorgos,
Its very simple & clear explanation, thank you.
From your explanation, can i say in different way that if r^2<1 meanings the straight line trend strength is just weakening (or model starts to change the direction) and r^2=1 means the model is not random. Is it correct?
Regards,
Ade
#6
Posted 30 January 2010 - 01:00 PM
Quote
Ade,
An R^2 can be roughly thought of as a % explanatory; also, any significant "R", will also denote whether the relationship is directly or inversely proportional, depending on whether it is positive or negative. In multiple regression forecasting, there will be multiple R's and R^2's. The "R" is used in forecast calculation.
In this case, Metastock is using TIME as the independent variable.
You will never see a real-world R^2 of 1. Also, keep in mind that both R and R^2 are NOT measures of a single data point.
--Johnathan
#7
Posted 31 January 2010 - 02:19 AM
singashari, on 30 January 2010 - 12:12 PM, said:
When r^2<1 it means that the closing prices do not move in a straight oblique line and as Johnathan said an r^2 equal to 1 is seldom in the real world. An r^2 equal to 1 yes it would mean that the price moves in a perfect straight oblique line and as such it does not have any random components. Theoretically however, you may have a low r^2 accompanied by a progressively stronger directional movement just because the movement does not follow a straight line.
Giorgos
#8
Posted 31 January 2010 - 12:19 PM
Siligard, on 31 January 2010 - 03:19 PM, said:
Giorgos
Giorgos,
I got the point now. I like to know whether you have coding to find out period of any indicator?
Thank you.
Regards,
Ade
#10
Posted 02 February 2010 - 03:14 PM
#11
Posted 02 February 2010 - 05:25 PM
singashari, on 02 February 2010 - 03:14 PM, said:
still haven't understood what you want Ade...
Do you want to find how many bars have passed since r^2>=8 for every stock?
Do you want to find how many bars back to take into account in the calculation of r^2 so that r^2>=8 if possible for every stock?
What do you mean by "period of securities"?
Perhaps somebody else can help...
Giorgos
#13
Posted 03 February 2010 - 01:29 PM
Siligard, on 03 February 2010 - 06:25 AM, said:
Do you want to find how many bars have passed since r^2>=8 for every stock?
Do you want to find how many bars back to take into account in the calculation of r^2 so that r^2>=8 if possible for every stock?
What do you mean by "period of securities"?
Perhaps somebody else can help...
Giorgos
Giorgos,
This is what i read from Metastock help.
r-squared values show the percentage of movement that can be explained by linear regression. For example, if the r-squared value over 20 days is at 70%, this means that 70% of the movement of the security is explained by linear regression. The other 30% is unexplained random noise.
One of the most useful way to use r-squared is as a confirming indicator. Momentum based indicators (e.g., Stochastics, RSI, CCI, etc.) and moving average systems require a confirmation of trend in order to be consistently effective. R-squared provides a means of quantifying the "trendiness" of prices. If r-squared is above its critical value and heading up, you can be 95% confident that a strong trend is present.
When using momentum based indicators, only trade overbought/oversold levels if you have determined that prices are trendless or weakening (i.e., a low or lowering r-squared value). Because in a strong trending market, prices can remain overbought or oversold for extended periods. Therefore, you may want to reconsider trading on strict overbought/oversold levels used by many indicators. An "overbought" market can remain overbought for extended periods in a trending market. However, a signal generated by a moving average crossover system may be worth following, since these systems work best in strong trending markets.
To determine if the trend is statistically significant for a given x-period linear regression line, plot the r-squared indicator and refer to the following table. This table shows the values of r-squared required for a 95% confidence level at various time periods. If the r-squared value is less than the critical values shown, you should assume that prices show no statistically significant trend.
Based on e.g. r^2(20) = 70%, what I mean about the coding I like to know coding to find period of r^2 which equal to 70% and as e.g is 20 days.
The idea is I like to see correlation r^2 with momentum indicators & moving average to make profit. I believe Metastock team build the indicator based on some experiences, so they can explained on Metastock Help.
Thank you
Regards,
Ade
experience
Regards,
#14
Posted 03 February 2010 - 01:36 PM
JohnathanStein, on 03 February 2010 - 06:57 AM, said:
--Johnathan
Johnathan,
Why I interested with this indicator, because some indicators is worked un-consistently ( I didn't check all indicators yet). So, I found something interesting on Metastock Help, which is r^2. The idea is I like to confirm my indicator so the indicator performance will improved.
Thank you.
Regards,
Ade
#16
Posted 03 February 2010 - 02:57 PM
Indicator Name: _R2
Period:=Input("Period",1,120,20);
MinSlope:=Input("Minimum Slope",.01,.5,.05);
CriticalValue:=If(Period>=120,.03,If(Period>=60,.06,If(Period>=50,.08,If(Period>=30,.13,If(Period>=25,.16,If(Period>=20,.20,If(Period>=14,.27,If(Period>=10,.40,If(Period>=5,.77,0)))))))));
Trend:=If(RSquared(C,Period)>CriticalValue,1,0);
Direction:=If(LinRegSlope(C,Period)>=MinSlope,1,If(LinRegSlope(C,Period)<=-MinSlope,-1,0));
If(Trend>0 AND Direction>0,1,If(Trend>0 AND Direction<0,-1,0));
R2.png (29.48K)
Number of downloads: 17
--Johnathan
#17
Posted 04 February 2010 - 01:18 PM
JohnathanStein, on 04 February 2010 - 03:57 AM, said:
Indicator Name: _R2
Period:=Input("Period",1,120,20);
MinSlope:=Input("Minimum Slope",.01,.5,.05);
CriticalValue:=If(Period>=120,.03,If(Period>=60,.06,If(Period>=50,.08,If(Period>=30,.13,If(Period>=25,.16,If(Period>=20,.20,If(Period>=14,.27,If(Period>=10,.40,If(Period>=5,.77,0)))))))));
Trend:=If(RSquared(C,Period)>CriticalValue,1,0);
Direction:=If(LinRegSlope(C,Period)>=MinSlope,1,If(LinRegSlope(C,Period)<=-MinSlope,-1,0));
If(Trend>0 AND Direction>0,1,If(Trend>0 AND Direction<0,-1,0));--Johnathan
Johnathan,
Thank you for your coding. Actually I don't apply the method yet & I just start it.
I am wondering, is there possible we modified the coding by iteration. For example, if R^2(C,period)<0.8 then period=period+1 continue until we get R^2 >=0.8. Is it possible?
Regards,
Ade
#18
Posted 04 February 2010 - 02:32 PM
singashari, on 04 February 2010 - 02:18 PM, said:
Ade -- You really, really, really need to use it and learn more about how Metastock works.
Specifically, how to plot indicators on a chart, so you can see what they do, and how to use indicators in an Exploration.
It will also be helpful to you to create/attach an Expert, and to modify Indicators used in Experts.
I worked up the code to give you a "leg up" on these things, but there is no shortcut anyone can give you in learning to do them; it just takes time & experience. You have to know/learn the basics of Metastock's features.
singashari, on 04 February 2010 - 02:18 PM, said:
I don't think you quite understand how to use indicators, as your question does not make sense.
--Johnathan
#19
Posted 05 February 2010 - 04:03 PM
singashari, on 04 February 2010 - 01:18 PM, said:
Ade, now I think I got what you want.
In Metastock help there is a table which contains 9 periods for r^2 along with their corresponding critical values. If you want to find which period gives an r^2 greater than its critical value you don't need to use iteration (loop). Just calculate the r^2 for these nine periods and check which one is greater than its critical value.
If however you want to use a specific value (say 0.80) for every period and you want to check say 200 different periods (from 10 to 210) to find those which will produce an r^2 of greater value than the specific 0.80 you will surely need iteration which is not possible in Metastock formula language. You will need an external dll function to accomplish this.
Hope this helps.
Giorgos
#20
Posted 08 February 2010 - 06:30 PM
JohnathanStein, on 05 February 2010 - 03:32 AM, said:
Specifically, how to plot indicators on a chart, so you can see what they do, and how to use indicators in an Exploration.
It will also be helpful to you to create/attach an Expert, and to modify Indicators used in Experts.
I worked up the code to give you a "leg up" on these things, but there is no shortcut anyone can give you in learning to do them; it just takes time & experience. You have to know/learn the basics of Metastock's features.
I don't think you quite understand how to use indicators, as your question does not make sense.
--Johnathan
Johnathan,
I think I need more experience since I am new on Metastock. Many thank you, for the explanation.
Regards,
Ade

Sign In
Register
Help

MultiQuote