Global Variables versus FileWrite - page 3

 

@deysmacro

But I'm still struggling to see any reason why people don't want to use ChartID()? Does it sometimes change? Does it sometimes duplicate itself?

Otherwise, why would I reinvent the wheel by adding lines of code instead of DoubleToStr(ChartID(),0)?

 

@angevoyageur

Thanks again for the reply.

I apologise for being unclear to everybody.

I understand what Magic numbers are, and I understand what ChartID() does.

I'm just trying to find the best way to create a unique GV name that won't be changed, can be recovered after a terminal restart and doesn't need to be known by any other EA instance.

ChartID() seems to fit the bill, but people keep suggesting far more complicated ways of doing this. Which is why I'm confused.

 
toast:

Thanks again for the reply.

I apologise for being unclear to everybody.

I understand what Magic numbers are, and I understand what ChartID() does.

I'm just trying to find the best way to create a unique GV name that won't be changed, can be recovered after a terminal restart and doesn't need to be known by any other EA instance.

ChartID() seems to fit the bill, but people keep suggesting far more complicated ways of doing this. Which is why I'm confused.


Have a name generator for GV and then check whether the unique GV name existed or not. That's all.

When you use ChartID(), you are not in control but using name generator, you are in control.

If you still find that using ChartID() is good, then, please do so.

I am putting a dot here.

 

Well, thank you for your help anyway.

If I generate the name for the GV, how would it be retrieved after a terminal restart? It'd have to be in another GV, or deduced from user inputs which can be changed...

I think I will go with ChartID().

All these other options seem to be writing code for the sake of it.

In the absence of any real reason why ChartID() is a bad idea, I'll stick with it.

 
toast:

Well, thank you for your help anyway.

If I generate the name for the GV, how would it be retrieved after a terminal restart? It'd have to be in another GV, or deduced from user inputs which can be changed...

I think I will go with ChartID().

All these other options seem to be writing code for the sake of it.

In the absence of any real reason why ChartID() is a bad idea, I'll stick with it.

ChartID() seems a good idea for creating a unique name, you only have to check that this ID is persistent across MT4 restart. I never checked that.

Let us know.

 
angevoyageur:

ChartID() seems a good idea for creating a unique name, you only have to check that this ID is persistent across MT4 restart. I never checked that.

Let us know.



Yes, it is. I checked that earlier on today.

First run:

After terminal restart:

 
if the chart has been closed and reopen you lost your previous ChartED()
 

Yes, if you have closed that particular chart (while keeping the rest of the terminal open) the ID is lost.

But if the chart gets closed because the whole terminal has been closed, the ID will remain the same when the terminal is reopened.

 

i would use the account number or a number derived from it. I wouldnt trust ChartID, what if user has to reinstall MT4 or accidentally closes chart while trades are opened. The number of the account that has the EA's open trades is robust.

 
SDC:

i would use the account number or a number derived from it. I wouldnt trust ChartID, what if user has to reinstall MT4 or accidentally closes chart while trades are opened. The number of the account that has the EA's open trades is robust.


I already told toast to create a unique name generator though.