Download MetaTrader 5

Global Variables versus FileWrite

To add comments, please log in or register
Toast
226
Toast  

I have about 8-10 variables that cannot be recalculated on the fly without substantial aggravation (they are derived from iCustom calls potentially long past).

Considering that I normally run 5-10 instances of the EA per terminal and I want to create a level of persistence, which is my better option for reliability and speed:

1. Global Variables; or

2. FileWrite

I'm sure I'll be able to figure out what I need to do with either system, but I'm unclear which is the best avenue to pursue.

Any thoughts will be greatly appreciated.

Alain Verleyen
Moderator
32828
Alain Verleyen  
toast:

I have about 8-10 variables that cannot be recalculated on the fly without substantial aggravation (they are derived from iCustom calls potentially long past).

Considering that I normally run 5-10 instances of the EA per terminal and I want to create a level of persistence, which is my better option for reliability and speed:

1. Global Variables; or

2. FileWrite

I'm sure I'll be able to figure out what I need to do with either system, but I'm unclear which is the best avenue to pursue.

Any thoughts will be greatly appreciated.

Global Variables of the terminal are more easy to use, you can also change them manually within the terminal. But writing to a file is more flexible.
qjol
3243
qjol  
angevoyageur:
But writing to a file is more flexible.

but more reliable
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  

Global Variables can be reliable if you code your ea properly. Same thing for writing to a file.

Nothing is reliable if your ea code is not done properly to handle Global Variables or writing to a file.

Global Variables or writing to a file are just flavors to your taste actually.

qjol
3243
qjol  

you are right !!!

i remember the times (a few years back) when Global Variables has been saved to a file only by closing the terminal

which means if there is a crash of terminal/computer/power, they have not been saved

it seems that things have changed since then and now they are saved immediately to a file

thanks for the info

Toast
226
Toast  
Thank you very much for the prompt replies everybody - quick and informative, as always!
SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  
qjol:

you are right !!!

i remember the times (a few years back) when Global Variables has been saved to a file only by closing the terminal

which means if there is a crash of terminal/computer/power, they have not been saved

it seems that things have changed since then and now they are saved immediately to a file

thanks for the info


GV is becoming more reliable these days.

Nice isn't it? I hope MetaQuotes can make it even nicer. :)

Toast
226
Toast  

If I can trouble you guys with another question:

Is using ChartID() a reliable way for naming global variables? Is it always unique, and doesn't change once assigned to a particular chart?

I was thinking of using a combination of magic number and Symbol(), but my concern is that somebody changes the magic number with active trades. If this happens, then the GVs used in managing the trades won't be correctly retrieved.


(Please note: I don't share GVs across different charts/EAs so I don't need to worry about another EA being able to retrieve the GV. I'm using them merely for persistence)

SYED NAUFAL GADDAFI
1399
SYED NAUFAL GADDAFI  
toast:

If I can trouble you guys with another question:

Is using ChartID() a reliable way for naming global variables? Is it always unique, and doesn't change once assigned to a particular chart?

I was thinking of using a combination of magic number and Symbol(), but my concern is that somebody changes the magic number with active trades. If this happens, then the GVs used in managing the trades won't be correctly retrieved.


(Please note: I don't share GVs across different charts/EAs so I don't need to worry about another EA being able to retrieve the GV. I'm using them merely for persistence)


Magic number can't be change once it is in orders (pending or market).
Toast
226
Toast  

Thanks for the reply.

Yes, I agree.

But the problem will be as follows:

A trade is opened with magic number 123.

When managing this trade, the EA will be looking for GV with name 123xxxxxx

Now the user changes the EA setting for magic number to 789 while the trade is still active.

So now the EA is looking for GV with name 789xxxxx (which doesn't exist).

Essentially, I'm looking for a GV naming convention that can't be modified by user input.

Alain Verleyen
Moderator
32828
Alain Verleyen  
toast:

Thanks for the reply.

Yes, I agree.

But the problem will be as follows:

A trade is opened with magic number 123.

When managing this trade, the EA will be looking for GV with name 123xxxxxx

Now the user changes the EA setting for magic number to 789 while the trade is still active.

So now the EA is looking for GV with name 789xxxxx (which doesn't exist).

Essentially, I'm looking for a GV naming convention that can't be modified by user input.

Don't allow to change the magic number if there are still open trades with old magic.
123456
To add comments, please log in or register