signal versus indicator code and use of globalvariable.dll

Questions about MultiCharts and user contributed studies.
faschim
Posts: 37
Joined: 14 Jul 2009
Has thanked: 5 times

signal versus indicator code and use of globalvariable.dll

Postby faschim » 14 Jul 2011

I had some indicator code in which I was using the recalculate() function on the last bar in such a way that all data was run through the indicator code twice. This is done by using some of the functionality of GlobalVariable.dll (specifically GVGetNamedInt and GVSetNamedInt) to keep track of the number of times the indicator has has made a complete pass through the data (complete in the sense that the code accounts for hidden or user initiated recalculations).

All was well until I tried using some of this methodology in strategy code. It would appear that in a "recalculation" in the context of a strategy, multicharts does some sort of an almost hidden chart reload, i.e. GlobalVariables.dll is reloaded and hence the values stored in globalvariable.dll are lost between recalculations. Not sure though.

Any enlightenment (on how MC differs with indicator and strategy code) or other ideas to get around this problem.

arjfca
Posts: 1292
Joined: 23 Nov 2010
Has thanked: 725 times
Been thanked: 223 times

Re: signal versus indicator code and use of globalvariable.d

Postby arjfca » 14 Jul 2011

Have you tried to define your variable using

Var: IntraBarPersist MyVariable (0);

At the beginning of each recalculation, all variables are reset to their initial value. If some of your variables are not linked or rely to the actual bar, then you may need to keep the calculated value using IntraBarPersist.

Martin

faschim
Posts: 37
Joined: 14 Jul 2009
Has thanked: 5 times

Re: signal versus indicator code and use of globalvariable.d

Postby faschim » 15 Jul 2011

Thanks for the suggestion. What I was describing above is a different situation, i.e. I am using the recalculate() function to run through historical data numerous times (for example to calculate various statistics over the entire time period and then use these values in a subsequent pass through the data). All easylanguage variables are reset (including intrabarpersist variables) in this situation. Hence my use of global variables stored in a dll. Which works fine unless the dll is unloaded and then re-loaded on a recalculate. In indicator code it appears that dll's are not unloaded when a recalculate() is executed, however, in signal code it appears that dll's are reloaded on each recalculate, hence I lose values. This "reloading" would appear to be the behavior anyway. No other explanation that I can think of.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: signal versus indicator code and use of globalvariable.d

Postby Dave Masalov » 15 Jul 2011

faschim,

This is normal behavior. As a workaround, please try to write a simple indicator with one function addressing GlobalVariable.dll and make it auto-applied to all your charts. Thus, it will keep the dll always active and prevent it from reloading.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Re: signal versus indicator code and use of globalvariable.d

Postby 2haerim » 16 Jul 2011

This is normal behavior. As a workaround, please try to write a simple indicator with one function addressing GlobalVariable.dll and make it auto-applied to all your charts. Thus, it will keep the dll always active and prevent it from reloading.
faschim,

This is normal behavior. As a workaround, please try to write a simple indicator with one function addressing GlobalVariable.dll and make it auto-applied to all your charts. Thus, it will keep the dll always active and prevent it from reloading.
Dave,

It's good to have a workaround. But would you be explaining why signals reload while indicators does not? The explanation might be quite technical but somehow it will be a good help how MC works differently with indicators and signals, and so on.

thx

faschim
Posts: 37
Joined: 14 Jul 2009
Has thanked: 5 times

Re: signal versus indicator code and use of globalvariable.d

Postby faschim » 18 Jul 2011

Many thanks for the workaround Dave. That fixed the issue. What I ended up doing was in the "dummy indicator" I use GVSetNamedInt to store the aiAppId (with a silly long name for the "named" bit that would never be accidently used elsewhere). I then have an easylangue function (returning true/false) that I can call in my code where recalculations are taking place to check and see if GlobalVariable.dll is loaded (by calling GVGetNamedInt and checking for the error code) and if it is loaded then checking to see if it is loaded on a different chart by checking current aiAppId versus that stored in GlobalVariable.dll (of course that doesn't exactly work if for some reason I last applied the "dummy indicator" to the recalculating chart in question - but its good enough).

I agree with the previous post, it would be good to have a general explantion in regards to the differences between how multicharts handles signal and indicator code. Also, it would seem that an old version (< v2.2) of GlobalVariable.dll is distributed with MultiCharts. I always have to replace when upgrading to a later version or beta. Its there a reason for this?

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Re: signal versus indicator code and use of globalvariable.d

Postby Spaceant » 19 Jul 2011

faschim,

This is normal behavior. As a workaround, please try to write a simple indicator with one function addressing GlobalVariable.dll and make it auto-applied to all your charts. Thus, it will keep the dll always active and prevent it from reloading.
I think it will resolve the issues that I have been facing in which I tried to pass through a signal from one non-IOG-enabled strategy to another non-IOG-enabled one that have been applied to the chart. It appeared that the signal only passed through to the others with a one-bar delay. I have been searching for a solution, but failed.

Could anyone comment that the above mentioned solution could solve the issues that I have been facing?

Could anyone post an example here to let us learn?

Sa


Return to “MultiCharts”