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

Notification

Icon
Error

Options
Go to last post Go to first unread
garykong  
#1 Posted : Saturday, May 13, 2006 11:23:47 AM(UTC)
garykong

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/30/2005(UTC)
Posts: 112

Hi all, I am writing a few (at least three as I am thinking now) indicators that calculates on two variables that may vary in days or weeks, say A & B. Also, I will develop another set of indicators similarly for another index. I know that I can code in by inputting the variables individually in each indicator, like... A:=Input("DSFactor",-200,200,0); {that is used by 1st set of index} B:=Input("DHFactor",-200,200,0); {that is used by 2nd set of index} I have thought that it may work if I develop a reference indication that inputs the variables:-
{REFERENCE IND} A:=Input("DSFactor",-200,200,1); {that is used by 1st set of index} B:=Input("DHFactor",-200,200,1); {that is used by 2nd set of index} A;B
then use the "FmlVar" to recall the variable for the coding after the plugging in 50 for A and 100 for B in "REFERENCE IND". DSF:= FmlVar("REFERENCE IND","A") But it fails as the recalled A & B are always set to be "1".............. I know that I can plug inindividually, but for at least 6 times (1 variables each x 3 indicators x 2 sets). That's troublesome and may introduce errors!! Instead of inputting them individually each time for the full set of indicators when the variables vary, what is the efficient way to coding them?? thanks in advance!
johnl  
#2 Posted : Tuesday, May 16, 2006 12:15:03 AM(UTC)
johnl

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 11/7/2005(UTC)
Posts: 602

Anybody can correct me if I am wrong: What you really want is to be able to "pass a parameter" to a MS formula that is also a parameter. Nope, uses it's "default value" when referenced within another formula. Can not think of any way to get around your problem. Sorry.
Jose  
#3 Posted : Tuesday, May 16, 2006 11:26:33 AM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
There is a way around this with the GV.dll available from MetaStockTools.com. It stores variables in RAM, so that user inputs can be accessed by other formulae. Perhaps Roy from MetaStock Tips and Tools may be able to explain more about this process. jose '-)
mstt  
#4 Posted : Tuesday, May 16, 2006 9:43:43 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)
Gary I'll be working on examples using the GV dll later today. You could install the GV now so that the examples work immediately they're pasted into the Indicator Builder. Roy MetaStock Tips & Tools
garykong  
#5 Posted : Wednesday, May 17, 2006 10:02:01 AM(UTC)
garykong

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/30/2005(UTC)
Posts: 112

Jose wrote:
There is a way around this with the GV.dll available from MetaStockTools.com. It stores variables in RAM, so that user inputs can be accessed by other formulae. Perhaps Roy from MetaStock Tips and Tools may be able to explain more about this process. jose '-)
Jose, Thanks for your advice! Gar
garykong  
#6 Posted : Wednesday, May 17, 2006 10:13:10 AM(UTC)
garykong

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/30/2005(UTC)
Posts: 112

mstt wrote:
Gary I'll be working on examples using the GV dll later today. You could install the GV now so that the examples work immediately they're pasted into the Indicator Builder. Roy MetaStock Tips & Tools
Roy, Firsly, thanks for helping me! Well, how to install the GV:-- Copy the gv.dll (http://forum.equis.com/drm_main.php?mode=drm_cat_view&cat=8) into Equis\\MetaStock\\External Function Dlls Am I right?? Also, I look forward to test your example. Gar
mstt  
#7 Posted : Wednesday, May 17, 2006 7:50:34 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)
Gary Yes, copy GV.DLL into C:\\..\\MetaStock\\External Function Dlls Pathnames differ but the last two folders in the path must be as you suggest. Other work has delayed my getting to the examples I promised but I have not forgotten you. Roy
mstt  
#8 Posted : Friday, May 19, 2006 12:07:12 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)
Making Constants Available Globally This exercise demonstrates how to take a standard indicator with one or more Input() functions and modify it to use global variables instead of having to rely on Input() function defaults. A Compensated Linear Regression Slope indicator is used in each exploration column, and a conventional version of the indicator is also shown below for your interest. Inputs to a specially constructed indicator are used to set a selection of constants which are then saved as global variables. This same indicator may be used to immediately retrieve these constants and plot them on an open chart for verification. It can be helpful to plot a sine wave or some other obvious signal in addition to the user’s constants because horizontal lines might not be visible when un-scaled. The indicator should be deleted from the chart once the constants have been verified as correct. It can be pulled down again at any time the "global" constants need to be changed. Global variables are lost when MetaStock is closed so constants stored by this method must be set up prior to use in each MetaStock session. Making an asterisk {*} the first character of the "* GV Set Constants" indicator ensures that this indicator resides at the top of the drop-down indicator list and is therefore easy to find. The use of LastValue() when calling global variables makes these values available as constants, and they can then be used as "periods" parameters. The procedure for making global variables available as "global constants" is as follows. 1. Pull down the "* GV Set Constants" indicator onto any open chart 2. Set required values for all constants using the "Parameters" window. 3. Refresh the chart. 4. Verify that displayed constants are the correct values (place cursor on any plot to view data window). 5. Delete the "* GV Set Constants" indicator from open chart(s). Never use Fml("* GV Set Constants") to access any global variables. This will restore saved constants back to the (probably unwanted) Input() defaults. Until you are confident in using the above procedures it can be reassuring to have an extra indicator that only DISPLAYS global variables and CAN NOT change them. See below for "* GV Get Constants". If you need assistance in adapting this method to your particular requirements then please write to me directly at rlarsen@man.quik.co.nz . Roy MetaStock Tips & Tools {----------8<----------} {* GV Set Constants} {GV.DLL courtesy of Mark Pyle} {© 2006 Roy Larsen} {www.metastocktips.co.nz} {Use to set constants as global variables.} {Pull down, set values, refresh chart,} {verify, delete indicator, use constants.} GV1:=Input("Set Constant 1 - GV1",-999,999,20); GV2:=Input("Set Constant 2 - GV2",-999,999,20); GV3:=Input("Set Constant 3 - GV3",-999,999,20); GV4:=Input("Set Constant 4 - GV4",-999,999,20); GV5:=Input("Set Constant 5 - GV5",-999,999,20); GV6:=Input("Set Constant 6 - GV6",-999,999,20); {Set user constants to GV.DLL} A:=ExtFml("GV.SetVar","GV1",GV1); A:=ExtFml("GV.SetVar","GV2",GV2); A:=ExtFml("GV.SetVar","GV3",GV3); A:=ExtFml("GV.SetVar","GV4",GV4); A:=ExtFml("GV.SetVar","GV5",GV5); A:=ExtFml("GV.SetVar","GV6",GV6); {Get user constants from GV.DLL} GV1:=LastValue(ExtFml("GV.GetVar","GV1")); GV2:=LastValue(ExtFml("GV.GetVar","GV2")); GV3:=LastValue(ExtFml("GV.GetVar","GV3")); GV4:=LastValue(ExtFml("GV.GetVar","GV4")); GV5:=LastValue(ExtFml("GV.GetVar","GV5")); GV6:=LastValue(ExtFml("GV.GetVar","GV6")); {Plot user constants} GV1; GV2; GV3; GV4; GV5; GV6; {Plot sine wave to ensure indicator visibility} Sin(Cum(5)); {----------8<----------} {----------8<----------} {Compensated LRS} {© 2003-2006 Roy Larsen} {www.metastocktips.co.nz} Pds:=Input("LRS Periods",1,999,10); LinRegSlope(WC(),Pds)*1000/WC(); {----------8<----------} {----------8<----------} {Exploration notes} {Sample exploration to demonstrate the use of global variables with purpose-built "indicator" formulas} {Col A:} Pds:=LastValue(ExtFml("GV.GetVar","GV1")); LinRegSlope(WC(),Pds)*1000/WC(); {Col B:} Pds:=LastValue(ExtFml("GV.GetVar","GV2")); LinRegSlope(WC(),Pds)*1000/WC(); {Col C:} Pds:=LastValue(ExtFml("GV.GetVar","GV3")); LinRegSlope(WC(),Pds)*1000/WC(); {Col D:} Pds:=LastValue(ExtFml("GV.GetVar","GV4")); LinRegSlope(WC(),Pds)*1000/WC(); {Col E:} Pds:=LastValue(ExtFml("GV.GetVar","GV5")); LinRegSlope(WC(),Pds)*1000/WC(); {Col F:} Pds:=LastValue(ExtFml("GV.GetVar","GV6")); LinRegSlope(WC(),Pds)*1000/WC(); Filter enabled Yes Periodicity Daily Records required 100 {----------8<----------} {----------8<----------} {* GV Get Constants} {© 2006 Roy Larsen} {www.metastocktips.co.nz} {Get user constants from global var DLL} GV1:=LastValue(ExtFml("GV.GetVar","GV1")); GV2:=LastValue(ExtFml("GV.GetVar","GV2")); GV3:=LastValue(ExtFml("GV.GetVar","GV3")); GV4:=LastValue(ExtFml("GV.GetVar","GV4")); GV5:=LastValue(ExtFml("GV.GetVar","GV5")); GV6:=LastValue(ExtFml("GV.GetVar","GV6")); {Plot user constants} GV1; GV2; GV3; GV4; GV5; GV6; {Plot sine wave to ensure indicator visibility} Sin(Cum(5)); {----------8<----------}
garykong  
#9 Posted : Sunday, June 4, 2006 3:17:15 PM(UTC)
garykong

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 4/30/2005(UTC)
Posts: 112

Hi Roy, I have been busy these days. Finally, I have tried your GV dll and it works perfectly as what I want...... Well, is there any limitation of the number of variables (those GV1 .... GV6)? Also, any other usage for your GV Dll?? Thanks in advance! Gary
mstt  
#10 Posted : Sunday, June 4, 2006 9:26:39 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)
Hi Gary First, the GlobalVar dll (GV.DLL) was created by Mark Pyle, so any accolades should go to him. My contribution has only been to come up with new uses for it. In answer to you question, no, there's no hard limit on the number of global variable arrays or constants you can have. In terms of uses with the Input() function, twelve is probably a practical limit for any one indicator setting up the constants to start with. This is because it gets much more difficult to split a combined number back into its constituents when there are more than two numbers to be extracted. Sorry, I can't find any working examples right at the moment. Roy MetaStock Tips & Tools
nobel_1101  
#11 Posted : Saturday, September 8, 2007 10:17:29 AM(UTC)
nobel_1101

Rank: Member

Groups: Registered, Registered Users
Joined: 5/17/2005(UTC)
Posts: 24
Location: London

Thanks Roy. Useful post. I'm building an expert advisor and this was exactly what I was looking for.

[:)]

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.