Global Scope Variable vs. GlobalVariable...()?

 

Dear All,

Kindly explain to me what are the main differences between the variables declared in the global scope of the program and GlobalVariable...()?

Another question is jumping in my mind as per the following case ...

I understood that, "Global variables of the client terminal are accessible simultaneously from all MQL4 programs launched in the client terminal".

so; suppose that; the same EA is attached to more that one chart (Assuming that FIXED Symbol() but different Time-Frames say H1 & H4);

Taking into considerations that, my GlobalVariable...() is being updated and override by the local code inside the int start() function.

Now; Let my GlobalVariable...() for H1-chart is directing my EA to go long and open buy positions upon certain criteria.

Is that value of my GlobalVariable...() will force the same EA to go long on the H4-chart also, although it might be the buying criterion for H4 is NOT exist yet?

Are they holding by separate buffers or what?

Please help and advice.

 

Variables are held in memory, Global Variables are stored in files. If you think of a GlobalVariable as a file it might help you get a better grasp.

If you need different GlobalVariables for different timeframes you will need to name the GlobalVariables differently for each timeframe . . . if you also need different GlobalVariables for different currencies you will also need them named differently in that case too . . before long you will end up with many, many GlobalVaraibles.

Maybe you should look at the way you are using GlobalVariables and decide if there is a better way to do what you are doing . . if not then be happy.

 
OmegaFX:

Taking into considerations that, my GlobalVariable...() is being updated and override by the local code inside the int start() function.

Now; Let my GlobalVariable...() for H1-chart is directing my EA to go long and open buy positions upon certain criteria.

Is that value of my GlobalVariable...() will force the same EA to go long on the H4-chart also, although it might be the buying criterion for H4 is NOT exist yet?

Are they holding by separate buffers or what?

IF your EA is updating a GlobalVariable("x") on the H1 chart, so is it updating it on the H4. There is only one "x".

If your EA reads GlobalVariable("x") on the H1 chart and that value results in a long, then it will also read the same value in the H4 for going long also.

If depends on what you're code is doing with the variable. No mind readers here. Explain what you are trying to do and why.

"Are they holding by separate buffers or what?" Huh? Speak complete sentences.

 
WHRoeder:

"Are they holding by separate buffers or what?" Huh? Speak complete sentences.

I'm sorry for my incomplete question.

I just wanted to check out what you've already confirmed in your valuable answer, " There is only one x "

I was suspecting that; MT holds different value for each time-frame for each variable just like accessing the indicator buffers no matter which chart is already attached.

RaptorUK:

Maybe you should look at the way you are using GlobalVariables and decide if there is a better way to do what you are doing . . if not then be happy.

For sure, I'd be happy by following your advice in order to avoid getting lost with the unlimited versions of my variables, and there's no good reason for sacrificing the flexibility of my variables upon changing time-frames.

 
OmegaFX:

I was suspecting that; MT holds different value for each time-frame for each variable just like accessing the indicator buffers no matter which chart is already attached.

MT4 only holds the variables you specifically create.
Reason: