global variable in MC can be only used in Real time?

Questions about MultiCharts and user contributed studies.
elvis1984
Posts: 6
Joined: 19 Sep 2013
Has thanked: 1 time

global variable in MC can be only used in Real time?

Postby elvis1984 » 10 Nov 2013

I found that global variable cant store the value in history but only the current latest value, which make the strategy back testing impossible to finish. For instance,
You insert this indicator in one workspace:
vars:GVset("GVtest"),var1(0);//

GVSetNamedDouble(Gvset,0);
if time=1500 then begin GVSetNamedDouble(Gvset,close);
var1=close;
end;

plot1(var1);

And then insert the below indicator in another workspace:

var:GVget("GVtest"),var0(0);

var0=GVGetNamedDouble("GVtest",-9999);

plot1(var0);

You may get the latest close price on 15:00, but no the days before.

How to trace the history value by GV? thanks!

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: global variable in MC can be only used in Real time?

Postby TJ » 10 Nov 2013

I found that global variable cant store the value in history but only the current latest value, which make the strategy back testing impossible to finish. For instance,
You insert this indicator in one workspace:
vars:GVset("GVtest"),var1(0);//
GVSetNamedDouble(Gvset,0);
if time=1500 then begin GVSetNamedDouble(Gvset,close);
var1=close;
end;
plot1(var1);
And then insert the below indicator in another workspace:
var:GVget("GVtest"),var0(0);
var0=GVGetNamedDouble("GVtest",-9999);
plot1(var0);
You may get the latest close price on 15:00, but no the days before.
How to trace the history value by GV? thanks!
What is your chart resolution?
Depends on your code, you should be able to check for var0[1].

If not, then you have to save the past data in an array.



ps.
[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713

elvis1984
Posts: 6
Joined: 19 Sep 2013
Has thanked: 1 time

Re: global variable in MC can be only used in Real time?

Postby elvis1984 » 11 Nov 2013

What I mean is the global variable is a constant when you use it, which make the back testing failed. var0[1] can only return the value one bar ago, but the value has not change in the very beginning. Anyone know what I am saying?

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: global variable in MC can be only used in Real time?

Postby JoshM » 11 Nov 2013

I found that global variable cant store the value in history but only the current latest value, which make the strategy back testing impossible to finish.

(...)

How to trace the history value by GV? thanks!
Global variables don't work with backtesting, as far as I know. Creating a list with ELCollection does work. You can find the ELCollection and documentation here. There are multiple topics about/that use ELCollection, for example this topic and this topic (do a search for more).

elvis1984
Posts: 6
Joined: 19 Sep 2013
Has thanked: 1 time

Re: global variable in MC can be only used in Real time?

Postby elvis1984 » 11 Nov 2013

Thanks, That is what I want. I will spend more time to figure out this.


Return to “MultiCharts”