Global Variables versus FileWrite - page 2

 
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.


Do not hide magic number.

The simple way is to tell your users what magic number is, they will know how to deal with it.

 
angevoyageur:
Don't allow to change the magic number if there are still open trades with old magic.


Such as when there are no open orders, then the change will take effect. If there are still open trades, user still can change but will not take effect.


That logic can be done pretty easy actually.

 

Thanks for the reply.

I guess that is possible, but a little messy? The only way I can think of doing that is loop through the orders and check there are no open orders. If that is the case, then apply input int MagicNumber to int NewMagic

Or is there an easier way?

The ChartID() seems a lot easier, is there a problem with using it?

 

I think I was posting at the same time as a few others...

@fxMeter - if they want to use the EA on multiple charts, then I need some way to keep changing the magic number without running into duplicates. Which then brings us right back around to GVs again.

@deysmacro - I think we were thinking of the same solution

But again - this all seems like a lot of work if ChartID() can be used?

 
toast:

I think I was posting at the same time as a few others...

@fxMeter - if they want to use the EA on multiple charts, then I need some way to keep changing the magic number without running into duplicates. Which then brings us right back around to GVs again.

@deysmacro - I think we were thinking of the same solution

But again - this all seems like a lot of work if ChartID() can be used?


Lot of work at first. Then little work to do once implemented.

Coding are always like that. :)

 
I agree that it can be done, but again I'm wondering why people are against using ChartID()? Is there something wrong with it?
 
toast:
I agree that it can be done, but again I'm wondering why people are against using ChartID()? Is there something wrong with it?

https://forum.mql4.com/62102
 

Thanks for the link, but I don't think that problem would apply to me - I'm not looking at communicating the ChartID to any other instances of the EA.

I just want to know if ChartID() is a reliable, unique identifier of the current chart to use as a GV name?

 
toast:

Thanks for the link, but I don't think that problem would apply to me - I'm not looking at communicating the ChartID to any other instances of the EA.

I just want to know if ChartID() is a reliable, unique identifier of the current chart to use as a GV name?


Better have identifier built into your ea. From there you can do many things and it is reliable.
 
toast:

Thanks for the link, but I don't think that problem would apply to me - I'm not looking at communicating the ChartID to any other instances of the EA.

I just want to know if ChartID() is a reliable, unique identifier of the current chart to use as a GV name?


magic number and ChartID() are totally different things. magic is registered with your trade on server side. ChartID() is only to identify a chart in your current instance of the terminal.

Reason: