Global Variables Question

Questions about MultiCharts and user contributed studies.
User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Global Variables Question

Postby ym » 28 Feb 2010

I have just started to use GV to share infos between my strat's inputs and my indicators.
And it works great (how could I live without it ...) !

The problem is that my indic does NOT refresh AUTOMATICALLY when I change an input value in my strat.
In fact, I have to switch off/on the indic for it to refresh properly.

Is there any way to have the indic update automatically from a change in my strat ?

Here's excerpts of EL code from my strat and my indic :

Code: Select all

1- STRAT
// init Global_Variables
value1=GVSetNamedDouble("EMA_Fast_UT1", EMA_Fast_UT1);
value1=GVSetNamedDouble("EMA_Med_UT1",EMA_Med_UT1);
value1=GVSetNamedDouble("EMA_Slow_UT1",EMA_Slow_UT1);

2- INDIC
inputs:
Price( Close ),
Displace( 0 ) ;
variables:
var0( 0 ),
var1( 0 ),
var2( 0 );
value1=GVGetNamedDouble("EMA_Fast_UT1",value4);
value2=GVGetNamedDouble("EMA_Med_UT1",value4);
value3=GVGetNamedDouble("EMA_Slow_UT1",value4);
var0 = XAverage( Price, value1);
var1 = XAverage( Price, value2);
var2 = XAverage( Price, value3);
condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "FastAvg" ) ;
Plot2[Displace]( var1, "MedAvg" ) ;
Plot3[Displace]( var2, "SlowAvg" ) ;
end;
Thanks for your help.
Yann

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 28 Feb 2010

Have you thought about maybe sending macro commands to refresh the chart (using Global Variables to keep it from cycling)? That seems like it might be a way to go.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

Bruce,

Does 'refreshing the chart' imply to "reload" the data"?

If so, that's quite a long process (actually, I use multi time frames, including a 1mn, on a ONE-month backtesting period).
Normally, when you off/on an indic, it refreshes quite instantly in the chart ....

But I can give it a try.
I am not familiar with those macro commands that you mentioned ... what would you suggest me to do ?

Yann

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 28 Feb 2010

You're right, if reloading the data would take too long, it may not be a good solution. I can check to see what commands are available, but I don't think there's access as granular as cycling the status on an individual indicator.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

A quite naive question :

How come it is such a big deal to graphically update and refresh an indicator that is fed from GV inputs, whereas it is so straightforward and swift when one enters manually his/her own inputs ???

That puzzles me ...

Yann

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 28 Feb 2010

Because an indicator could potentially take a long time to calculate (depending on what's inside of it, obviously) MultiCharts is built intelligently to only recalculate it if something it depends on has changed. In this case, nothing has so it does not update - MultiCharts has no way of knowing the indicator uses a strategy as its input.

See also http://forum.tssupport.com/viewtopic.php?t=7191.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

I got your point quite well Bruce, but then why modifying manually the inputs of, for example, EMAs produces INSTANT results (despite the huge number of calculations that are involved on a one-month period with 1-min bars) ?

It looks that my problem could rather be that GV usage does not TRIGGER the initial refresh of my indicator.

Just a stupid question : do you think that might be ALSO due to the fact that today is sunday and the system awaits ticks from the market feed that don't come in ?

Yann

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 28 Feb 2010

EMA is an extremely efficient operation, in that it does not require any lookback - only to know its own previous calculated value.

That is correct, the problem is the indicator recalc does not trigger because MC does not know that it should (it doesn't know you're using GV).

Real-time market data is not involved.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

That is correct, the problem is the indicator recalc does not trigger because MC does not know that it should (it doesn't know you're using GV).
>
Do you have any suggestion ?
Yann

User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times
Contact:

Postby Bruce DeVault » 28 Feb 2010

Edit: I've made a post noted above requesting a feature be added to make this easier in the future.
Last edited by Bruce DeVault on 01 Mar 2010, edited 1 time in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

I saw that you have just made a suggestion to MC on that subject ...
Thanks for your support and replies, Bruce.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 28 Feb 2010

Maybe you need to use the recalculate command. I use this on almost every single indicator and normally I trigger it from my database program but I have one study that triggers it in another study.

I got the command from the list of unsupported reserve words.
http://forum.tssupport.com/viewtopic.ph ... ed+reserve

You barely notice it happening. It restarts your study from the first bar on the chart just as if you started up MC for the day.

Unfortunately some of the code wraps around.

Code: Select all

variables:
GV_Recalc(""),
MySym("");

if CurrentBar = 1 then
Begin
MySym = leftstr(getsymbolname,2);
Value1 = GVSetNamedString("Calc_RSI_--" + MySym,"N");
end;

if LastBarOnChart_s then
begin
GV_Recalc = GVGetNamedString("Calc_RSI_--" + MySym,"N");
if GV_Recalc = "R" then
begin
recalculate();
end;
end;
So it should be obvious that some other study or program sets the value to "R" and you get the recalculate. Pretty simple stuff. Why they do not support this command I can't guess. It is mentioned in my case study. If you exceed the maxbarsback MC automatically does this to get the new MaxBarsBack setting so why would they not support this command. It is the reason I use MC (I am not kidding).

I have probably 100 to 200 inputs to my studies that come from the database program rather than from MC's rather slow method of changing inputs. In my mind to use MC without knowing at least the basic language is very limiting.
Last edited by bowlesj3 on 28 Feb 2010, edited 2 times in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

Bowles,

I am not quite sure I understood it all well.

1- The code you sent me is to be included in my indicator, is that right ?
2- My strat should manage to set the value to "R", is that right ?
3- What "MySym" is supposed to do in your code ? Let's assume my indic's name is "indic01", what should I use instead of '"Calc_RSI_--" + MySym' ?
4- I don't have access to GV2.2 but only the basic MC GV. Can I substitute "GVGetNamedString" and "GVSetNamedString" with "GVGetNamedDouble" and "GVSetNamedDouble" and numeric values instead of "N" and "R" (for example 0 and 1) ?

Thanks.
Yann

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 28 Feb 2010

Hi Ym,

I just included the getsymbol command. I trade two symbols. I need it for that. Yes your one study sets the value R (or whatever) and the second study detects that value and does the recalculate. When the first bar on the chart is processed after the recalculate is issued it sets the "R" back to "N" so your study does not go into an infinite loop. I did that once. I forgot to reset it back to "N" and sure enough MC locked right up and I had to cancel it from windows.

Yes, so study #1 sets the R, study #2 detects the R and does the recalculate and study #2 on the first bar of the chart has to reset that GV back to "N". If study #2 does not set it back to "N" it will cause all of MC to lock up. Yes I use GV 2.2. I would use that if I was you. Here is the thread.

http://forum.tssupport.com/viewtopic.php?=&p=8189

John.
Last edited by bowlesj3 on 28 Feb 2010, edited 1 time in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

Bowles,
Okdokey ... I'll try that one and come back to you if any pb.
Thanks++
Yann

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 28 Feb 2010

No probs. The GV 2.2 thread is in there now. I included a post to that thread to show how to use the map commands which can get pretty confusing.
John.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

John,

It doesn't work, the indic does not auto refresh.

Here's my EL code :

Code: Select all

=======
1- STRAT
=======
// init GV to auto recalc indic
Value2=88;
Value1 = GVSetNamedDouble("recalc_tag",value2);

======
2- INDIC
======
inputs:
Price( Close ),
Displace( 0 ) ;

variables:
var0( 0 ),
var1( 0 ),
var2( 0 );

value2=88;
if CurrentBar = 1 then GVSetNamedDouble("Recalc",value2);

value1=GVGetNamedDouble("EMA_Fast_UT60",value4);
value2=GVGetNamedDouble("EMA_Med_UT60",value4);
value3=GVGetNamedDouble("EMA_Slow_UT60",value4);

var0 = XAverage( Price, value1);
var1 = XAverage( Price, value2);
var2 = XAverage( Price, value3);

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "FastAvg" ) ;
Plot2[Displace]( var1, "MedAvg" ) ;
Plot3[Displace]( var2, "SlowAvg" ) ;
end;

if CurrentBar = 1 then
begin
value2=77;
Value1 = GVSetNamedDouble("recalc_tag",value2);
end;

if LastBarOnChart_s then
begin
value3 = GVGetNamedDouble("recalc_tag",value4);
if value3=88 then
begin
recalculate();
end;
end;
What's the pb ?
Yann

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 28 Feb 2010

Oops, slight correction ...
Here's the code :

Code: Select all

=======
1- STRAT
=======
// init GV to auto recalc indic
Value2=88;
Value1 = GVSetNamedDouble("recalc_tag",value2);

======
2- INDIC
======
inputs:
Price( Close ),
Displace( 0 ) ;

variables:
var0( 0 ),
var1( 0 ),
var2( 0 );

value1=GVGetNamedDouble("EMA_Fast_UT60",value4);
value2=GVGetNamedDouble("EMA_Med_UT60",value4);
value3=GVGetNamedDouble("EMA_Slow_UT60",value4);

var0 = XAverage( Price, value1);
var1 = XAverage( Price, value2);
var2 = XAverage( Price, value3);

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "FastAvg" ) ;
Plot2[Displace]( var1, "MedAvg" ) ;
Plot3[Displace]( var2, "SlowAvg" ) ;
end;

if CurrentBar = 1 then
begin
value2=77;
Value1 = GVSetNamedDouble("recalc_tag",value2);
end;

if LastBarOnChart_s then
begin
value3 = GVGetNamedDouble("recalc_tag",value4);
if value3=88 then
begin
recalculate();
end;
end;
What's the pb ?
Yann

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 28 Feb 2010

Hi YM

If you currently have a live feed and you are sure the first study is executing the setnameddouble (use a print statement to double check this and be sure) then it should work. If you are using minute bars remove the _s from LastBarOnChart.

Note, Maybe use a fileappend statement since the recalculate resets the print statement but I think that the recalculate does not reset the fileappend statement. You need to put a newline NL at the end of fileappend.

Again I use GV 2.2. I also do not use the function but rather use the GV_setnamedstring command directly (notice that there is an underscore after the GV). You can see this if you open up the GV functions. You may as well install the GV 2.2. It is not hard.

Keep at it. Trust me. The recalculate command works. One of my studies executes it over 1000 times a day and I need to revisit it to figure out how to reduce that. It runs so fast that I do not even see it running it.


Here is another way to be sure. Put these play sound statements in the first study and in the second study just before the recalculate statement.
Playsound("C:\WINDOWS\Media\Ding.wav");
Playsound("C:\WINDOWS\Media\Windows XP Battery Critical.wav");
There are more of them in the media directory.
You will hear them and they tell you want code is working.

You can also debug by copying the get command from the second study into the first study and put it in a print statement and that will tell you that the get command is picking up the GV set command value.

John.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 01 Mar 2010

John,

It works great now !

I am not quite sure if this is related to the market feed being active or not (it's now Monday morning here in Paris and the market is active, whereas it was not yesterday).

Anyway now it works, and FYI it works great with the basic MC GV (numeric variables only).
So far, I did not have to download the GV2.2 ... but I will surely do it sooner or later.

BTW, what is the difference between LastBarOnChart_s and LastBarOnChart ?

Thanks.

Yann

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 01 Mar 2010

LastBarOnChart_s for seconds bars (up to 6 digits) and LastBarOnChart is for bars larger than seconds (only 4 digits max).
I am not quite sure if this is related to the market feed being active or not (it's now Monday morning here in Paris and the market is active, whereas it was not yesterday).
Because of the above quote it sounds like you really need to hit the manuals YM. Press F1 in MC to get to them. The powerlanguage help is critical to read right through command by command reading what they do and taking notes of things that sound useful. Do that 2 or 3 times over the next 2 or 3 years. Do the same thing with all the stuff you find when you open up to find signals, indicators, functions. For example LastBarOnChart_s is a function. You can go in to the editor and find it in the list of functions and open it to see what it has.

Yes for sure it was because there were no ticks coming through. You need a tick(a trade) to execute the code after all the historic bars are filled out. When you changed the first study to set the "R" for recalc (or your number) the second study never picked it up because no ticks were coming through to cause that second study to execute. So when you open up MC on the weekend it executes your study once for each bar that gets put on the chart when BarStatus=2 and it stops there. It only executes that lastbaronchart once in that case. However during live trading it executes the lastbaronchart over and over even though the bar is not finished (if you have checked to execute on every tick).

It is very handy to have a program such as PowerBasic or FreeBasic or whatever to control GVs external form MC.

Have fun.
John.
Last edited by bowlesj3 on 01 Mar 2010, edited 5 times in total.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 01 Mar 2010

Good advice ;-)
Thanks.
Yann

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 01 Mar 2010

I added another paragraphe YM. You might have missed it. Maybe a reread.
John.

User avatar
ym
Posts: 53
Joined: 26 Feb 2010

Postby ym » 01 Mar 2010

I have got something for you that can't be sent here, nor in a PM.
Send me a PM with your email, if you're ok with that ...


Return to “MultiCharts”