- Question About Global(scope) Variables of indicators
- My approach. The core is the engine.
- not to lose variable value when changing timeframe or re-connect in INDICATOR?
Just as an EA uses a Magic Number to identify its own trades, use a "Magic Prefix" for the global terminal variables to differentiate one instance from another.
This "magic prefix" can either be set as a fixed parameter input, or it can be constructed to include the chart symbol and time-frame, and any other unique identifier, that will help minimise the multiple occurrences when using the same indicator on multiple charts. You can also use a combination of both a fixed input tag and the symbol, time-frame, etc.
Hey guys, I coded something and had to use global variables because when I switched timeframes the program re initialized and all as it does and I needed some variables to not lose their values when reinitialized. I am not talking about global variables in termes of scope but global variables like using GlobalVariableSet() function. It helped me overcome that problem of storing values of variables when Indicator is reinitialized but what I am experiencing is that when I have multiple charts with the indicator on it, when I change a value, it changes value of that variable on all the opened charts which is logical. But I want to know if there’s a way to stop that? Thanks in advance
Add the chart id to the variable names.
That is acceptable but not always ideal. If you close a chart and later reopen a new chart on the same symbol and time-frame, you may want to carry over the previous data, and it will fail if the chart id is different.
It really depends on whether the OP wants to only keep data live while for the duration of the chart life or if he wants the data to persist into a future reopening of the symbol / time-frame / etc. conditions.
That is acceptable but not always ideal. If you close a chart and later reopen a new chart on the same symbol and time-frame, you may want to carry over the previous data, and it will fail if the chart id is different.
It really depends on whether the OP wants to only keep data live while for the duration of the chart life or if he wants the data to persist into a future reopening of the symbol / time-frame / etc. conditions.
No, there is a misunderstanding on your part. Using a Chart ID of "0", tells the functions to use the "current chart", but it does not signify that the chart's actual id is 0. The chart's actual ID is usually a large number (e.g. 132683146766314648).
However, I still suggest using a more "human" readable prefix for global terminal variables, as it will be easier for you to follow up on the variables, in the Global Variables Window (F3), and also to modify values or delete older variables.
If you just use the ID, you will have difficulty identifying which chart is which just from the ID reference alone.
However, I still suggest using a more "human" readable prefix for global terminal variables, as it will be easier for you to follow up on the variables, in the Global Variables Window (F3), and also to modify values or delete older variables.
If you just use the ID, you will have difficulty identifying which chart is which just from the ID reference alone.
No, there is a misunderstanding on your part. Using a Chart ID of "0", tells the functions to use the "current chart", but it does not signify that the chart's actual id is 0. The chart's actual ID is usually a large number (e.g. 132683146766314648).
Yes, that makes sense, but it really depends on how your Indicator reacts to chart changes.
If the indicator needs to reset data if you change time-frame, then it is best to keep track of the time-frame in the prefix. It it keeps that data, then it will be best NOT to use the time-frame in the prefix.
The same applies to the Symbol. If the Indicator needs to reset for a symbol change, then keep the symbol name in the prefix, but if it keeps the data regardless of the symbol, then don't use the symbol name in the prefix.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use