Configure (Variable)
The Variable Configure Tab is used to set the data type and scope of a Variable.
Variable Type
A variable is used to store some useful information (or data). Its type is defined by the kind of data that needs to be saved.
A datatype is simply a section of memory used to store a value.
The MQL data types are:
Integer (int): An integer is a whole number. A whole number means the number does not have a decimal point. For example, the number of total open trades is an integer: 0, 1, 2 …. There is no concept of 1.5 open trades. However, the balance of a MetaTrader account is a number with a decimal point - such as 10,000.99. A number with a decimal point is called a real number in the field of mathematics. A real number data type is called a double in MQL.
Double (double): A double is a real number. A real number means the number has a decimal point. The balance of a MetaTrader account is a real number - such as 10,000.99.
Boolean (bool): A boolean is a data type that can one of two values: true or false.
String (string): A string is one or more characters. A string value is set using double quotes. For example: message=”Hello World”.
Void (void): A void type is a “nothing” type. It is used in to indicate that no data type is inferred.
Date and Time (datetime): A datetime data type is used to store calendar dates and times. The data type itself is actually an integer. The current time is an integer whose value is the number of seconds elapsed since midnight January 1, 1970. (This is a common approach, used in many computer languages, to define the current time.)
Color (color): A color data type is actually an integer type. This data type is defined to make color assignments easy.
Variable Scope
The word scope is used in programming to define the visibility of a data structure. That is, if a variable has global scope it can be accessed from anywhere within the program. If a variable has function scope it can only be accessed within the function that it is defined.
The levels of variable scope in VTS are:
extern: A extern variable is available as input to an Expert Advisor.
global: A global variable saves its value between Expert Advisor invocations.
system: A system variable is accessible from any function of an Expert Advisor.
function: A function variable is only accessible from the function where it is defined.
parameter: A parameter variable is used to send or receive data to or from a function. The variable is only accessible from the function where it is defined. Note: a parameter variable can be set in Function Drawings only, not on the main system drawing.