Problem using global variable

 

I have a problem... I declared an array outside any function, so, the scope of this array is global.
Execute the EA and I save and load data from this array on a pair, for example EURUSD without problems but, the problem is when I execute the same Expert Advisor on 2 or more pairs, the data is combined and I don't know if the data that I´m getting is from EURUSD, GBPUSD or another one, what can I do?

Beforehand, thank you. 

 

Global scope 

 

Are you sure about this?

A globally declared array is only global to the instance of the EA. It should not be possible to access that array from the same EA attached to a different chart.

 

Yes, I'm totally sure

I have been trying other simple things and this is happening

Code 

---------------------------------------------------------------------------------------------

001 

---------------------------------------------------------------------------------------------------------------------

002 

 
Rogelio Rosales: the problem is when I execute the same Expert Advisor on 2 or more pairs, the data is combined
You are not running it on "2 or more pairs" you are switching pairs and your code only adds to the array. You never clear out on init. You'll get duplicates when you just change timeframes.
 
Rogelio Rosales: Yes, I'm totally sure I have been trying other simple things and this is
Please note that the function OrderTotal() returns the total number of open orders for the entire account. It has no relationship with the Chart you have the EA running, so it does not filter by Currency pair or by Time-frame or by Magic number or anything else for that matter. It is simply the Total number of open orders for the entire account for all the running EAs as well as manual trades.
 
whroeder1:
You are not running it on "2 or more pairs" you are switching pairs and your code only adds to the array. You never clear out on init. You'll get duplicates when you just change timeframes.
It's true, first I executed the EA in EURUSD and next I tried it on GBPUSD 
 
Fernando Carreiro:
Please note that the function OrderTotal() returns the total number of open orders for the entire account. It has no relationship with the Chart you have the EA running, so it does not filter by Currency pair or by Time-frame or by Magic number or anything else for that matter. It is simply the Total number of open orders for the entire account for all the running EAs as well as manual trades.
Fernando Carreiro Yes, it is a mistake from me, sorry

But I did it  for try to explain my topic, in few words, I need create an array for every pair when the EA is running so the data not mixed  
 
Rogelio Rosales: Fernando Carreiro Yes, it is a mistake from me, sorry. But I did it  for try to explain my topic, in few words, I need create an array for every pair when the EA is running so the data not mixed  

The Data does not "mix". You must be doing something wrong, so show your real code if you want us to help!

To add samples don't use screen-shots; use the SRC button in the toolbar: 

If the code is long, then attach it instead (in the bottom-left):

 
Rogelio Rosales:

I have a problem... I declared an array outside any function, so, the scope of this array is global.
Execute the EA and I save and load data from this array on a pair, for example EURUSD without problems but, the problem is when I execute the same Expert Advisor on 2 or more pairs, the data is combined and I don't know if the data that I´m getting is from EURUSD, GBPUSD or another one, what can I do?

Beforehand, thank you. 

 

 

I have the same problem! i couldnt find any way other than changing variable names in each version! so the variables of different currencies not mix! but  this way is really annoying! is there any other simple way?
 
Pourya Ebrahimi #: I have the same problem! i couldnt find any way other than changing variable names in each version! so the variables of different currencies not mix! but  this way is really annoying! is there any other simple way?

Yes, by learning to code properly. Don't assign "data" to variable names. Assign data to the storage of the variables, not their names.

Create a structure for storing the data, including the symbol names, price, etc., then create an array of the structure.

You can also adopt OOP programming and use classes for more sophisticated needs.

Reason: