Global variables between indicators

Avinash Singh
795
Avinash Singh  

Hello,


Looking forward to some help with the indicator logic I am trying to build. The scenario is like this. I am planning to do a similar kind of calculation and use it across the charts. Since the calculation is going to be the same, I do not want to do it 12 times across all my charts, but rather do it once and then retrieve it in the other chart with individual indicators. This way I can avoid unwanted processing load on my cpu. I have no problem declaring the GlobalVariableSet() on the first indicator. I am also able to access this value using GlobalVariableGet() on the same chart. However, when I do the GlobalVariableGet() on a different chart with a different indicator, then I don't get the value.


Appreciate any help to guide me on how to set this up.

Thanks,

Ray
2646
Ray  

After setting a GlobalVariable, you should be able to get it without problem on other charts.


Check (or show here) your code.

Avinash Singh
795
Avinash Singh  
phy:

After setting a GlobalVariable, you should be able to get it without problem on other charts.


Check (or show here) your code.

Thanks Phy for the response. If I explain the problem in a better way, it is that while the Global variable is accessible from the other charts, it is that it is a single constant value and I cannot use it to draw a line. For example, in the code below, I get a straight line for the last 100 bars because there is no stored representation of the values for i-1, i-2 etc.

int start()
  {
      for(int i = 0; i < 100; i++)
      {
         1HEUUS[i] = GlobalVariableGet("1heu");
         4HEUUS[i] = GlobalVariableGet("4heu");
         1HUSCH[i] = GlobalVariableGet("1huc");
         4HUSCH[i] = GlobalVariableGet("4huc");
      }
         
//----
   return(0);
  }
Ray
2646
Ray  

If you want 100 different values stored in GlobalVariables, you need 100 different GlobalVariable names


for(int i = 0, i < 100; i++)

{

GlobalVariableSet("NameText"+i, value[i]);

}


---

For other indicators:

for(int i = 0, i < 100; i++)

{

GlobalVariableGet("NameText"+i, value[i]);

}


----

You might consider writing your values to a file, and having the other charts read from the file, instead of using GlobalVariables

Avinash Singh
795
Avinash Singh  
Thanks Phy. I am trying to work on the file functions and probably need to spend some time figuring out how it works. For the time being, I have implemented your suggestion and included "i" in the variable and am able to get the charts. Thanks for the help.