logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
jjstein  
#1 Posted : Sunday, June 25, 2006 1:57:24 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
The following indicator goes berserk in early 1998 -- any idea how to fix? It is supposed to calc MACD, based upon DOW historical data, then switch to actual data (ETF) when available. {MACD Input switched} FastPeriod:=Input("Fast periods:",1,250,12); SlowPeriod:=Input("Slow periods:",1,250,26); SignalPeriod:=Input("Signal periods:",1,250,9); x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); x1:=ExtFml("Forum.Sum",x1,1); x2:=ExtFml("Forum.Sum",x2,1); x3:=ExtFml("Forum.Sum",x2,30); x:=If(x3=0,x1,x2); MAFast:=Mov(x,FastPeriod,E); MASlow:=Mov(x,SlowPeriod,E); MyMACD:=MAFast-MASlow; MASignal:=Mov(MyMACD,SignalPeriod,E); MACDH:=MyMACD-MASignal; MACDH; MASignal; MyMACD; 0;
wabbit  
#2 Posted : Sunday, June 25, 2006 7:47:13 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
jjstein wrote:
The following indicator goes berserk in early 1998 -- any idea how to fix? It is supposed to calc MACD, based upon DOW historical data, then switch to actual data (ETF) when available.
What do you mean going beserk? Can you give a more descriptive definition of the problem? Can you post a chart showing the problem, may be with an annotation or two showing exactly where you think the error lies. It is not always possible for others on this world-wide forum to replicate the errors you mention, as not everyone subscribes to the same data. You should endeavour to help those from whom you are seeking help... wabbit :D
hayseed  
#3 Posted : Sunday, June 25, 2006 1:08:39 PM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey jj..... a question and thought...... your C:\\METASTOCK DATA\\.DJI",C, is that really the path name.... there is usually a sub folder like c:\\metastock data\\[color=red:f4bd8ad034]bm data\\[/color].dji ...... of course if your theory will work, using any two tickers should give the desired results.... theory being described as the ability to switch indicator targets mid stream..... not sure if thats possible.... once a indicator has chosen a target, ie my C:\\MetaStock Data\\etf\\smh, the indicator will not switch to the C:\\MetaStock Data\\etf\\dia when there is no smh data.... and that includes mandated targets such as your x1:=Security("C:\\METASTOCK DATA\\.DJI",C); , it should always plot the macd of the .dji, not switching to another ticker.... i changed the tickers and file paths to match mine here and the macd plots... it will not plot prior to the standard lag time of the chart data.... wabbits dll should fill in that gap if need be.... so bottom line, it plots the macd correctly but for only the initial target security , never switching......h correction..... jj ... when transfering the indicator from the longer chart to the shorter chart the indicators do have a brief period where they a very slightly out of phase ..... it clears up within 26 days....
jjstein  
#4 Posted : Sunday, June 25, 2006 3:40:35 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Here's the chart: Load options are 30,000, Display is 375. Scroll back so Jan 1998 is in the middle of the chart, and examine values for the MACD -- they go from the hunderds, to the thousands, then back to single digits. UserPostedImage
wabbit  
#5 Posted : Monday, June 26, 2006 1:18:44 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Well, there doesn't appear to be anything wrong with the code itself, well not that I can see. The switching of the indicators only happens after both of the external securities are fully loaded, so there is no problem there. The most likely culprit here is perhaps the data? Have you plotted the securities individually to see if the data itself makes sense? x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); Plot each of these and do a visual check to see if it makes sense. Maybe you have some corrupt data from somwhere? You might need to download a new historical data file? Its easiest to start with the simple things first. If the data files check out correctly, then this is not the cause and we will have to do some more digging around. Let us know how things go. wabbit :D
jjstein  
#6 Posted : Monday, June 26, 2006 2:59:10 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Wabbit - Data seems clean; FYI, this data ships w/Metastock, and is in the standard locations for U.S. stocks. It has occurred to me that perhaps the problem is with the range of the moving averages, as one data set is in the 10,000's and the other in the 100's -- even though they are subtracted, one range will be higher than the other. So, I've normalized the MACD calculation: Values should be -50 to +50 range-bound. Problem is still there, narrowed down to start near/after the DIA data starts, but I don't know why. <SIGH> --Johnathan {** _MACD Input switched **} x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); x1:=ExtFml("Forum.Sum",x1,1); x2:=ExtFml("Forum.Sum",x2,1); x3:=ExtFml("Forum.Sum",x2,300);{30-->300 to normalize, but no change} x:=If(x3=0,x1,x2); MAFast:=Mov(x,12,E); MASlow:=Mov(x,26,E); {***Normalize -- from Jose's code} ratio:=Min(MAFast,MASlow)/Max(MAFast,MASlow); Mac:=(If(MAFast>MASlow,2-ratio,ratio)-1)*100; MacdNorm:=(Mac-LLV(Mac,250))/(HHV(Mac,250)-LLV(Mac,250)+.000001)*100; {***} MASignalNorm:=Mov(MACDNorm,9,E); MACDHNorm:=MACDNorm-MASignalNorm; MASignalnorm-50; MACDnorm-50; MACDHnorm; 0; {***} UserPostedImage
wabbit  
#7 Posted : Monday, June 26, 2006 4:23:31 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
As the data is not the problem, the normalisation of the output might not necessarily be the simplest answer either. Have a look in the following code when the values will swing between x1 and x2, based on your x3 variable. x1:=ExtFml("Forum.Sum",x1,1); x2:=ExtFml("Forum.Sum",x2,1); x3:=ExtFml("Forum.Sum",x2,30); x:=If(x3=0,x1,x2); I am guessing the problems occur when the x3 variable is changing. You mentioned the problem is still there with the flatness at the start and end and the high peaks in the middle of the data. I will guess that x1 is 'in play' during the flat, and x2 is in play in the peaks, or the other way 'round. Normalising the output of the MACD will not solve this problem. The input data needs to be more closely matched, ie you need to normalise the lesser data to the range of the greater, or vice versa. So both data sets will have range to 10,000 or range to 100, not mixed. It doesn't matter which way you do it. wabbit :D
wabbit  
#8 Posted : Monday, June 26, 2006 4:32:35 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
I suppose the next thing to do is check the shape of the two curves, either before or after normalisation. If the two curves have the same shape, i.e. the same relative daily performance, then why do you need to chop to one index from another? If both indexes are going up at the same relative rate, or going down at the same relative rate, then taking MAs of the data is going to produce the same results, just on different scales... Although it might be an interesting exercise to solve the data problem, it might be time to rethink the strategy and function? wabbit :D
hayseed  
#9 Posted : Monday, June 26, 2006 11:38:53 AM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey j.... wabbits point is why your indicator worked for me with just a slight out of phase period, the 26 days.... my macds were almost the same anyway, i had changed the tickers from yours to a couple common etf's that were far closer in price..... using your exact tickers i see the area your refering to ..... the two macd's are hundreds of precent difference in value during that period..... that 26 day period is likely going to be hard to plot.....h
jjstein  
#10 Posted : Monday, June 26, 2006 1:44:12 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Since the data is closely correlated, that the normalized MACD should work, since it is range-bound to -50 & +50; don't see how the range of the base data should matter...the normalization DOES match the ranges. I suppose the code could be modified to multiply the DIA data by 100, but how does that help? The idea -- for backtesting purposes -- is to use the ETF data when available (since it is an actual product which can be bought), but for the period before it existed, to use the index upon which the ETF is based. DIA & .DJI are only ONE such pair; others could be QQQQ & Nasdaq, SPY & SP500, etc. The only other solution is to use the index, but since the money will go into the ETF, not the index, I want to use the actual product data. Anyway, if this works at all -- and except for that 26/300 day hole, it seems to plot OK -- it should be able to work CORRECTLY. --Johnathan
hayseed  
#11 Posted : Monday, June 26, 2006 2:34:03 PM(UTC)
hayseed

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 3/7/2005(UTC)
Posts: 1,346

hey j..... i tried various ratios, 10, 100 to get things more in tune, all it did was reduce the value your seeing..... now i see just what your purpose was, it's a neat concept..... it should allow your further back testing time..... below was my version of your indicator, which kinda works except for that small period.... but again this was using different tickers than yours..... no matter what i tried yours always had the 26 day whiplash deal.....h UserPostedImage
wabbit  
#12 Posted : Monday, June 26, 2006 2:56:55 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
It does work correctly - it works EXACTLY as you have coded it, and uses the data exactly as you provide it. You have just programmed it wrong.... Put some sample data into your code and see the effects for yourself... BARS 1 to 100 - Data values in the order of 100... using x1.... {** _MACD Input switched **} x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); x1:=ExtFml("Forum.Sum",x1,1); {in the order of 100} x2:=ExtFml("Forum.Sum",x2,1); x3:=ExtFml("Forum.Sum",x2,300);{30-->300 to normalize, but no change} x:=If(x3=0,x1,x2); {these MAs are in the order of 100} MAFast:=Mov(x,12,E); MASlow:=Mov(x,26,E); {***Normalize -- from Jose's code} ratio:=Min(MAFast,MASlow)/Max(MAFast,MASlow); Mac:=(If(MAFast>MASlow,2-ratio,ratio)-1)*100; MacdNorm:=(Mac-LLV(Mac,250))/(HHV(Mac,250)-LLV(Mac,250)+.000001)*100; {***} MASignalNorm:=Mov(MACDNorm,9,E); MACDHNorm:=MACDNorm-MASignalNorm; {These values turn out to be whatever?} MASignalnorm-50; MACDnorm-50; MACDHnorm; 0; {***} What happens on BAR 101 when the data swings over to x2.... of the order 10000? {** _MACD Input switched **} x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); x1:=ExtFml("Forum.Sum",x1,1); x2:=ExtFml("Forum.Sum",x2,1); {in the order of 10000} x3:=ExtFml("Forum.Sum",x2,300);{30-->300 to normalize, but no change} x:=If(x3=0,x1,x2); {for the first 100 bars the MAs are in the order of 100, but now adds a bar with 100000. Obviously the effect is going to be greatest on the fast MA than the slow MA} MAFast:=Mov(x,12,E); MASlow:=Mov(x,26,E); {Now what happens to the normalising process with massive jump from the previous values of the MAs and the disconnect of the data in the current MAs?} {***Normalize -- from Jose's code} ratio:=Min(MAFast,MASlow)/Max(MAFast,MASlow); Mac:=(If(MAFast>MASlow,2-ratio,ratio)-1)*100; MacdNorm:=(Mac-LLV(Mac,250))/(HHV(Mac,250)-LLV(Mac,250)+.000001)*100; {***} MASignalNorm:=Mov(MACDNorm,9,E); MACDHNorm:=MACDNorm-MASignalNorm; {These values turn out to be magnitude greater than before, distorting the plot} MASignalnorm-50; MACDnorm-50; MACDHnorm; 0; {***} and the process is reversed when the data swings back the other way. As you have a disparity between the large and small data values, you are better off scaling one to better match the magnitude of the other. If you want to swing MACDs, why not compute an MACD for each data set, then use your rules to change from one normalised MACD to the other? As my old boss said to me once, "Start thinking outside the box, instead of beating your head against it!" {** _MACD Input switched **} x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); x1:=ExtFml("Forum.Sum",x1,1); x2:=ExtFml("Forum.Sum",x2,1); x3:=ExtFml("Forum.Sum",x2,300);{30-->300 to normalize, but no change} x1MAFast:=Mov(x1,12,E); x1MASlow:=Mov(x1,26,E); x2MAFast:=Mov(x2,12,E); x2MASlow:=Mov(x2,26,E); x1ratio:=Min(x1MAFast,x1MASlow)/Max(x1MAFast,x1MASlow); x1Mac:=(If(x1MAFast>x1MASlow,2-x1ratio,x1ratio)-1)*100; x1MacdNorm:=(x1Mac-LLV(x1Mac,250))/(HHV(x1Mac,250)-LLV(x1Mac,250)+.000001)*100; x2ratio:=Min(x2MAFast,x2MASlow)/Max(x2MAFast,x2MASlow); x2Mac:=(If(x2MAFast>x2MASlow,2-x2ratio,x2ratio)-1)*100; x2MacdNorm:=(x2Mac-LLV(x2Mac,250))/(HHV(x2Mac,250)-LLV(x2Mac,250)+.000001)*100; x1MASignalNorm:=Mov(x1MACDNorm,9,E); x1MACDHNorm:=x1MACDNorm-x1MASignalNorm; x2MASignalNorm:=Mov(x2MACDNorm,9,E); x2MACDHNorm:=x2MACDNorm-x2MASignalNorm; {plot} x:=If(x3=0,x1MASignalnorm-50,x2MASignalnorm-50); x:=If(x3=0,x1MACDnorm-50,x2MACDnorm-50); x:=If(x3=0,x1MACDHnorm,x2MACDHnorm); 0; You might have to look at the changeover period to make sure the MACD for the second data set exists before the expiration of the first data set... but that shoulddn't be too much of an issue?? wabbit :D
jjstein  
#13 Posted : Monday, June 26, 2006 9:51:06 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Your "walk through" would be correct, except that my logic in using the code: x1:=ExtFml("Forum.Sum",x1,1); {order of 100} x2:=ExtFml("Forum.Sum",x2,1); {order of 10,000} x3:=ExtFml("Forum.Sum",x2,300);{30-->300 to normalize, but no change} x:=If(x3=0,x1,x2); ...is SUPPOSED to ensure that the data array, "x", would NEVER mix x1 and x2. That is its purpose in life. 1. Shouldn't BOTH of the MA's switch over to data set 2, when it has 300 elements? 2. If so, range-binding should keep things on a "similar" scale after switch over. Instead, the MACD "hangs" around near the MAX end of the scale, for almost a year. Why is this? --Johnathan
jjstein  
#14 Posted : Monday, June 26, 2006 10:08:02 PM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Had to modify your code just a bit (see below) to get it to work (I assume adding the +".000001" to the ratio divisions won't affect calcs much; also removed the "x:=" at bottom, {plot} area). 1. It SEEMS to shorten the problem area from a year and a half to a year. Still a problem, though. 2. Also, now the MACD "hangs" around in the "teen" (instead of the previous MAX) part of the scale. Why? --Johnathan {** _MACD Input switched **} {-50~+50%} x1:=Security("C:\\METASTOCK DATA\\.DJI",C); x2:=Security("C:\\METASTOCK DATA\\US STOCKS\\C - D\\DIA",C); x1:=ExtFml("Forum.Sum",x1,1); x2:=ExtFml("Forum.Sum",x2,1); x3:=ExtFml("Forum.Sum",x2,300); x1MAFast:=Mov(x1,12,E); x1MASlow:=Mov(x1,26,E); x2MAFast:=Mov(x2,12,E); x2MASlow:=Mov(x2,26,E); x1ratio:=Min(x1MAFast,x1MASlow)/(Max(x1MAFast,x1MASlow)+.000001); x1Mac:=(If(x1MAFast>x1MASlow,2-x1ratio,x1ratio)-1)*100; x1MacdNorm:=(x1Mac-LLV(x1Mac,250))/(HHV(x1Mac,250)-LLV(x1Mac,250)+.000001)*100; x2ratio:=Min(x2MAFast,x2MASlow)/(Max(x2MAFast,x2MASlow)+.000001); x2Mac:=(If(x2MAFast>x2MASlow,2-x2ratio,x2ratio)-1)*100; x2MacdNorm:=(x2Mac-LLV(x2Mac,250))/(HHV(x2Mac,250)-LLV(x2Mac,250)+.000001)*100; x1MASignalNorm:=Mov(x1MACDNorm,9,E); x1MACDHNorm:=x1MACDNorm-x1MASignalNorm; x2MASignalNorm:=Mov(x2MACDNorm,9,E); x2MACDHNorm:=x2MACDNorm-x2MASignalNorm; If(x3=0,x1MASignalnorm-50,x2MASignalnorm-50); If(x3=0,x1MACDnorm-50,x2MACDnorm-50); If(x3=0,x1MACDHnorm,x2MACDHnorm); 0; UserPostedImage
wabbit  
#15 Posted : Monday, June 26, 2006 11:46:34 PM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
Can you post a chart with the x1, x2 and x3 variables plotted (separate windows would be nice, but not mandatory)? Which version of the Forum.dll are you using? wabbit :D
jjstein  
#16 Posted : Tuesday, June 27, 2006 12:36:23 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
How do you tell the DLL version?
jjstein  
#17 Posted : Tuesday, June 27, 2006 12:49:16 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Here's the chart: UserPostedImage
wabbit  
#18 Posted : Tuesday, June 27, 2006 12:56:59 AM(UTC)
wabbit

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 10/28/2004(UTC)
Posts: 3,111
Location: Perth, Western Australia

Was thanked: 16 time(s) in 16 post(s)
jjstein wrote:
How do you tell the DLL version?
When you are in the Indicator Builder editing your code, there is a button on the bottom right "Functions" Press this button and it will open the Paste Functions window. Select the Froum dll from the list on the left. At the bottom of the window will be some copyright and hopefully version information about the product. Perhaps you could take a screen capture as well? wabbit :D P.S. Got SkyPE? - its a lot easier to talk than type!
jjstein  
#19 Posted : Tuesday, June 27, 2006 1:14:42 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Here's the screen capture: UserPostedImage
jjstein  
#20 Posted : Tuesday, June 27, 2006 1:16:59 AM(UTC)
jjstein

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/13/2005(UTC)
Posts: 715
Location: Midwest, USA

Was thanked: 1 time(s) in 1 post(s)
Tried Skype but don't use it, so it's un-installed. Give me an hour, will download, install and run out & get one of those little USB "Skype" phones at WalMart. --Johnathan
Users browsing this topic
Guest (Hidden)
2 Pages12>
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.