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

Notification

Icon
Error

Options
Go to last post Go to first unread
Gregor  
#1 Posted : Monday, July 25, 2011 2:34:44 PM(UTC)
Gregor

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/12/2007(UTC)
Posts: 32

Trying to get a input varialbe X in a custom indicator to appear in an expert commentry, but not getting the syntax right. When trying to apply the expert commentry formula I get an error message "This Funcation name does not exist in specified MSX DII. Could it be explained where I am going wrong? Source code below:

Your Turly

Gregor

{Custom Indicator}

x:=Input("Short Term Moving Average",7,14,7);
y:=Input("Envelopes Percentage variation",1,99,5)/100;
a:=x*5;

STMA:=Mov(C,x,E);
UB:=Mov(C,x,S)*(1+y);
LB:=Mov(C,x,S)*(1-y);
LTMA:=Mov(C,a,E);

STMA;
UB;
LB;
LTMA;

x:=ExtFml("GVf.SetVar","x",x);

{Expert Commentry}

Writeval( ExtFml("GVf.GetVal","x"))

jjstein  
#2 Posted : Monday, July 25, 2011 5:47:11 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)
Um, this might be simple, but...do you have a GVf.dll file in the "External Function DLLs" folder?

2. The 2nd item should be GetVar, with an "R", not GetVal with an "L".


mstt  
#3 Posted : Monday, July 25, 2011 11:36:27 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 Gregor Johnathan is correct in that the spelling of the GlobalVar function is GetVar, not GetVal. However that may not be the only problem you have. Before calling a global variable from the GlobalVar DLL (or any copy of it by another name) that variable must be populated with the correct data array values. If the correct data has not been loaded into the GV data array then you'll probably get garbage or data left over from a previous operation or chart. To set up the GV data array the indicator or formula that generates the data must first be called using an Fml() or FmlVar() function. To give you an example, all of my Trade Equity explorations that accumulate data in global variables include an Fml() function calling the relevant Trade Equity indicator as the very first step in column A of the exploration. The code below reads (GetVar function) a series of four global variables, but the "Eq" variable must first call the indicator that writes (SetVar function) the various GV data arrays with values relating to the current security. {Trade Equity Super Scan LE} {Col A: $ Profit} {Net profit} {Read TE LE global variables} Eq:=Fml("Trade Equity GV LE"); Cn:=ExtFml("GV.GetVar","Cn"); Cp:=ExtFml("GV.GetVar","Cp"); R:=ExtFml("GV.GetVar","Tr"); Xs:=ExtFml("GV.GetVar","Xs"); Hope this helps. Roy
jjstein  
#4 Posted : Tuesday, July 26, 2011 8:33:19 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)
Roy -- In his example, it looks the Chart Indicator is called first, then the Expert.

So...which gets executed first?


--Johnathan
mstt  
#5 Posted : Tuesday, July 26, 2011 2:45:49 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 Johnathan One could assume that Gregor's indicator is already plotted but the same assumption couldn't necessarily be made for another user struggling with a similar technique. Since an expert is usually based on a chart it follows that the chart is executed first. However this assumption is irrelevant when global variables are generated other than by the active chart. Roy
Gregor  
#6 Posted : Friday, July 29, 2011 12:26:39 PM(UTC)
Gregor

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 6/12/2007(UTC)
Posts: 32

Hi Roy & Johnathan

Correcting the spelling did the trick, but I've ran into anthor error problem. This time using the global variable to get Custom Indicator Gobal Bestup to reference its parameter from Custom Indicator Bands, I got the error message "This variable or expression must contain only constant data". Where have I gone wrong.

{Bands}

x:=Input("Short Term Moving Average",7,14,7);
y:=Input("Envelopes Percentage variation",1,99,5)/100;
a:=x*5;


STMA:=Mov(C,x,E);
UB:=Mov(C,x,S)*(1+y);
LB:=Mov(C,x,S)*(1-y);
LTMA:=Mov(C,a,E);

STMA;
UB;
LB;
LTMA;

{Gobal Variable}

I:=ExtFml("GVf.SetVar","Gx",x);
I:=ExtFml("GVf.SetVar","Gy",y*100);

{Gobal Bsetup}

Gx:=ExtFml("GVf.GetVar","Gx");
y:=5/100;

EMA:=Mov(C,Gx,E);
UB:=Mov(C,Gx,S)*(1+y);
LB:=Mov(C,Gx,S)*(1-y);
lta:=Mov(C,Gx*5, S); {Long term average}

I am also having diffculty understand the idea "Before calling a global variable from the GlobalVar DLL (or any copy of it by another name) that variable must be populated with the correct data array values". In your example you have variable Eq, I don't understant what variable I would use in my case.

Gregor

jjstein  
#7 Posted : Friday, July 29, 2011 12:55:44 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)
You will need to wrap "LastValue" around a variable with functions like MOV; Metastock treats most variables as arrays, and "LastValue" will truncate an array to the final element.

Make these changes, and your code will plot:

EMA:=Mov(C,LastValue(Gx),E);
UB:=Mov(C,LastValue(Gx),S)*(1+y);
LB:=Mov(C,LastValue(Gx),S)*(1-y);
lta:=Mov(C,LastValue(Gx*5), S); {Long term average}



mstt  
#8 Posted : Friday, July 29, 2011 4:06:01 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 Gregor Your "Gx" variable must provide a value that MetaStock accepts as a "constant", and enclosing it in LastValue() does that for you. {Gobal Bsetup} Gx:=LastValue(ExtFml("GVf.GetVar","Gx")); y:=5/100; EMA:=Mov(C,Gx,E); UB:=Mov(C,Gx,S)*(1+y); LB:=Mov(C,Gx,S)*(1-y); lta:=Mov(C,Gx*5, S); {Long term average} Re your other difficulty, if a global variable is called by an expert or an exploration and the indicator generating that global variable is NOT plotted on the current chart then the required global variable may not exist as a viable data array. It's only when you plot the custom indicator on a chart or call it in the expert (or exploration) that the GV SetVar function creates or refreshes the "Gx" and "Gy" global variables. Having your custom indicator present in the Indicator Builder but not called by a chart, expert or exploration means that MetaStock will not run the necessary sequence of code to generate the appropriate GV data arrays (Gx, Gy etc.). Once a custom indicator creates a set of global variables, those global variables remain constant until the generating indicator is plotted on another chart or called for another security. All global variables are lost when when MetaStock closes. Restarting MetaStock does not automatically generate any global variables - that will not and cannot occur until the MetaStock executes (calls, runs or whatever term you like to use) the indicator that generates the required global variables. Copying code created by someone else is a good way to get started with global variables, but understand that a global variable must be created before it can be used. Having the code in an indicator is only the first step - the indicator must be processed by MetaStock for it to create its global variables. Roy
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.