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

Notification

Icon
Error

Options
Go to last post Go to first unread
wmadani  
#1 Posted : Tuesday, June 27, 2006 5:07:20 PM(UTC)
wmadani

Rank: Member

Groups: Registered, Registered Users
Joined: 4/28/2006(UTC)
Posts: 10

Hi, How to calculate and plot the number of stocks- in a folder- that are above a certain percentage of a moving average ? Thanks
mstt  
#2 Posted : Tuesday, June 27, 2006 10:23:09 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
wmadani There are at least two ways to do this, and probably more. The task cannot be accomplished with the MetaStock Formula Language on its own though. The easiest method is probably to structure your exploration so that the state you want to count is reported as a TRUE (one). The completed report can be copied and pasted into Excel and the required columns summed. Creating a total in Excel should take about 10 seconds so it's not an onerous task. The second method requires the use of the Mark Pyle's GlobalVar dll (find it in the Downloads section). Some slightly more complicated code is required, including a supporting indicator or exploration to reset counter(s) before running the main exploration. The process reads the counter (a global variable cell for want of a better name), and then adds the result for the current security to the retrieved value and stores the new value. You will need either the reset indicator or reset exploration, but not both. The indicator, if used, should be dropped onto any chart and then deleted. It plots a sine wave simply to ensure that its plot is visible and can be easily seen for deletion. Its job is done once it has been dropped onto a chart. Leaving it on the chart would cause further resets each time the chart refreshed. The reset exploration only needs to be run on one security but no harm is done if it is batched and run on the same portfolio as the accumulation scan. These formulas demonstrate a principle that can be applied to sum many different vaules. Each globabl variable cell (or data array) must be reset prior to any attempt to accumulate data. Results from acummulating large numbers (such as volume or turnover) tend to be inaccurate once the total climbs above 6 significant digits. Neither MetaStock nor the GV dll were designed for double digit precision but summing small whole numbers is perfectly satisfactory. Exploration results are best sorted to ensure that the final value occurs at the end of the report. The order in which securities are presented to the Explorer can mean that results appear to be out of sequence and you should not assume that the last number appearing in any column is the highest number and represents the last security processed. You have been warned. {Tally Reset Indicator} {© 2006 Roy Larsen, www.metastocktips.co.nz} {* reset GV cell(s) before tally scan} A:=ExtFml("GV.SetVar","CountA",0); Sin(Cum(5)); {forces visible plot} {Tally Reset Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {* reset GV cell(s) before tally scan} ExtFml("GV.SetVar","CountA",0); {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {* accumulate state scan} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","CountA")); State:=C > Mov(C,14,S); Write:=Read + State; ExtFml("GV.SetVar","CountA",LastValue(Write)); I trust that this is of some help. Roy MetaStock Tips & Tools
hayseed  
#3 Posted : Wednesday, June 28, 2006 12:13:46 AM(UTC)
hayseed

Rank: Advanced Member

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

thanks roy.... now that's neat...... %'s above is something i run every single day...... my low tech method has been just watch the exploration run and at the completion right down the % rejected, which helps yield % above...... trouble is you only have about 2 seconds... can't tell ya how many times i watch the whole thing only to look away those last 2 "expletives deleted" seconds.... your way is much better..... and i can readily see more applications for that process..... thanks again.....h
mstt  
#4 Posted : Wednesday, June 28, 2006 1:03:39 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi H One thing I forgot to mention. ALL securities are evaluated when this approach is used. That's because any column accumulation occurs BEFORE the filter is activated. The filter can be activated on the last bar of any security, but that only happens AFTER columns A through F have been processed. Therefore, any required filter parameters must also be included as a filter in whatever state is being counted. In my example that would be as below. If that were not done you'd end up with a situation where the ascending count in a column could appear to skip one or more numbers. The missing numbers would be those relating to securities that were subsequently rejected by the exploration filter. State:=C > Mov(C,14,S) AND ("any required filter parameters"); I hope this makes sense. No action needs to be taken when the exploration filter is not active. Roy MetaStock Tips & Tools
hayseed  
#5 Posted : Wednesday, June 28, 2006 2:12:28 AM(UTC)
hayseed

Rank: Advanced Member

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

hey roy.... still workin with it..... i didn't notice any missing numbers but many times numbers would be duplicated.... there might be 3 securities number 5 and such..... checking the charts it seems only one was valid, the others didn't throw off the true total...... they were just there..... i don't use a filter, just watch the number of securities closing less than certain ma values..... here in the states, broad market turns often coincide with certain % levels...... it appears this is a one column only deal..... i tried to run all six columns but with different c>values by various means.... which included creating the companion reset indicator..... haven't been successfull.... it's still far better than my low tech 2 second approach...... thanks.....h
mstt  
#6 Posted : Wednesday, June 28, 2006 2:26:44 AM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
Hi H Non-incremented securities could be filtered out easily enough. If you were counting three columns for advances, delines and no-change, for example, you'd probably wouldn't want to filter any out anyway. There are many possibilities available, such as reporting zero for a security where no increment has occurred. I just presented the bare-bones code you'd need to get started. There should be no problem with multiple columns but each GV accumulator requires a different GV name. What I'm saying is that there are a whole bunch of traps you can fall into, but if you stop and think about what's happening there are logical explanations for such problems, and from there the solutions also tend to fall into place. Roy
hayseed  
#7 Posted : Wednesday, June 28, 2006 3:13:16 AM(UTC)
hayseed

Rank: Advanced Member

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

got it.... works perfect roy....thanks .... and thank you for the question wmadani..... we all learn from them......h [code:1:481661eda6]Exploration notes http://forum.equis.com/viewtopic.php?p=18633#18633 Col A: 5 {* accumulate state scan} {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","CountA")); State:=C > Mov(C,5,S); Write:=Read + State; ExtFml("GV.SetVar","CountA",LastValue(Write)); Col B: 10 {* accumulate state scan} {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","Countb")); State:=C > Mov(C,10,S); Write:=Read + State; ExtFml("GV.SetVar","Countb",LastValue(Write)); Col C: 15 {* accumulate state scan} {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","Countc")); State:=C > Mov(C,15,S); Write:=Read + State; ExtFml("GV.SetVar","Countc",LastValue(Write)); Col D: 20 {* accumulate state scan} {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","Countd")); State:=C > Mov(C,20,S); Write:=Read + State; ExtFml("GV.SetVar","Countd",LastValue(Write)); Col E: 40 {* accumulate state scan} {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","Counte")); State:=C > Mov(C,40,S); Write:=Read + State; ExtFml("GV.SetVar","Counte",LastValue(Write)); Col F: 50 {* accumulate state scan} {Tally Exploration} {© 2006 Roy Larsen, www.metastocktips.co.nz} {Column A: C>MA} {Issues above MA} Read:= LastValue(ExtFml("GV.GetVar","Countf")); State:=C > Mov(C,50,S); Write:=Read + State; ExtFml("GV.SetVar","Countf",LastValue(Write)); Filter colA OR colB OR colC OR colD OR colE OR colF Filter enabled Yes Periodicity Daily Records required 1000
Tally Reset Indicator {© 2006 Roy Larsen, www.metastocktips.co.nz} {* reset GV cell(s) before tally scan} A:=ExtFml("GV.SetVar","CountA",0); Sin(Cum(5)); {forces visible plot} A:=ExtFml("GV.SetVar","Countf",0); Sin(Cum(5)); {forces visible plot} A:=ExtFml("GV.SetVar","Countd",0); Sin(Cum(5)); {forces visible plot} A:=ExtFml("GV.SetVar","Counte",0); Sin(Cum(5)); {forces visible plot} A:=ExtFml("GV.SetVar","Countc",0); Sin(Cum(5)); {forces visible plot} A:=ExtFml("GV.SetVar","Countb",0); Sin(Cum(5)); {forces visible plot} [/code:1:481661eda6]
wmadani  
#8 Posted : Wednesday, June 28, 2006 5:37:26 PM(UTC)
wmadani

Rank: Member

Groups: Registered, Registered Users
Joined: 4/28/2006(UTC)
Posts: 10

Hello Roy, Thank you for your thorough reply to my question . I have run the following exploration on the Nasdaq100 as of close on June 27 : Read:= LastValue(ExtFml("GV.GetVar","Countd")); State:=C > Mov(C,20,S); Write:=Read + State; ExtFml("GV.SetVar","Countd",LastValue(Write)); and I have not used any filter; the above code was pasted in COLa , the result I got is 35 (double checked with other software to make sure that I have done it correctly) . Then; I pasted the same exploration code as an indicator and the plot I got was a horizontal line that reads 35 . My next step was to use the reset indicator and then refresh the chart and the value was reset as it suppose. So far so good BUT how to have a history plot for the past 1000 days loaded ,and not only for a single last day ? am I doing any thing incorrectly or that is the way its intended to be : A single day plot . Once again Thank you for taking the time to reply . H, Thank you for your input . Its really a great joy to read a dialogue between highly knowledgable people on questions submitted by MetaStock usrers. with my best Regards.
mstt  
#9 Posted : Wednesday, June 28, 2006 9:12:50 PM(UTC)
mstt

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/25/2005(UTC)
Posts: 1,042

Was thanked: 57 time(s) in 54 post(s)
wmadani Advance/decline history can be created for groups of securities such as the Nazdaq 100 using methods similar to those demonstrated earlier. The November 2005 issue of MSTT has an article that gives all the necessary details. The process is not perfect but it does produce approximate advance and decline figures for saving as A/D historical files. These files can be retrieved at any time by an indicator or exploration using the Security() function. Roy MetaStock Tips & Tools
Users browsing this topic
Guest (Hidden)
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.