Global variables definition

 
Hello,

I have global variables in an include file, defined like this


include.mqh

double variable1 = 5;

then I use this include for different indicators, eas and scripts.


script 1

#include <include.mqh>

indicator 1

#include <include.mqh>

expert 1

#include <include.mqh>

If I initialize the variable from any code, ea for example, 

expert 1

#include <include.mqh>

variable1 = 10;

the variable value is not shared with the other indicators or scripts.


The only way to do this that I have found is to use global variables (GlobalVariableSet), but then they are created in the global variable system and can be modified by the user.

I don't want the user to be able to modify them.


Is there any system of global variables, other than using GlobalVariableSet?


Thank you

 

These kind of global variables are valid only in their program (EA,script,..).

Global variables of the terminal are set and used with these extra functions: https://www.mql5.com/en/docs/globals

Documentation on MQL5: Global Variables of the Terminal
Documentation on MQL5: Global Variables of the Terminal
  • www.mql5.com
Global Variables of the Terminal - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Carl Schreiber #:

These kind of global variables are valid only in their program (EA,script,..).

Global variables of the terminal are set and used with these extra functions: https://www.mql5.com/en/docs/globals

Yes I know about terminal global variables, but is there any way of use them, but not allow user modify them?

 
powerbucker:
Hello,

I have global variables in an include file, defined like this


include.mqh

then I use this include for different indicators, eas and scripts.


script 1

indicator 1

expert 1

If I initialize the variable from any code, ea for example, 

expert 1

the variable value is not shared with the other indicators or scripts.


The only way to do this that I have found is to use global variables (GlobalVariableSet), but then they are created in the global variable system and can be modified by the user.

I don't want the user to be able to modify them.


Is there any system of global variables, other than using GlobalVariableSet?


Thank you

first get the global variable on OnInit

double value=GlobalVariableGet("value");

and save this value as a static variable in indicator or EA

static double svalue = value;

then check if its modified, keep checking on OnTick or OnCalculate

if(svalue !=GlobalVariableGet("name") ) {
GlobalVariableSet("name","svalue");
}

it modified, set it again the value from static variable and force update Global variable, in this case even if user modified it will automatic update. I have not compiled, just written for reference

 
Arpit T #:

first get the global variable on OnInit

and save this value as a static variable in indicator or EA

then check if its modified, keep checking on OnTick or OnCalculate

it modified, set it again the value from static variable and force update Global variable, in this case even if user modified it will automatic update. I have not compiled, just written for reference

good idea, I'll try


Thanks

Reason: