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.
signal versus indicator code and use of globalvariable.dll
Re: signal versus indicator code and use of globalvariable.d
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
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
Re: signal versus indicator code and use of globalvariable.d
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.
- 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
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.
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.
Re: signal versus indicator code and use of globalvariable.d
Dave,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.
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
Re: signal versus indicator code and use of globalvariable.d
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?
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?
Re: signal versus indicator code and use of globalvariable.d
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.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.
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