Creating A Counter that is Global only to that EA

 

I am having an issue which I suppose should be extremely simple but I cannot solve it. Here is my EA:


int counter = 1;

OnTick(){

do stuff with counter;

}


My problem is, every time I launch another EA on a different pair, it changes my counter back to 1 in every EA. Obviously I know this is because the variable is global, but the only command I can find for making the variable local is "static" and I have tried it without success. I cannot set the counter inside OnTick because it would constantly reset it every tick. So my problem is creating a variable which is global only to this EA but not being changed by all the other EA's on other pairs.

The Fundamentals of Testing in MetaTrader 5
The Fundamentals of Testing in MetaTrader 5
  • www.mql5.com
The idea of ​​automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
 

The other EA's don't change the counter, each EA has it's own instance of the counter, set to one in it's OnInit().

If you want one counter shared by all EA's you can use Terminal global variables

Documentation on MQL5: Language Basics / Variables / Global Variables
Documentation on MQL5: Language Basics / Variables / Global Variables
  • www.mql5.com
Global variables are created by placing their declarations outside function descriptions. Global variables are defined at the same level as functions, i.e., they are not local in any block. The scope of global variables is the entire program. Global variables are accessible from all functions defined in the program. They are initialized to zero...
Reason: