EA programming tutorial eighth variable (2)


1 local cashback forexs: variables defined inside the forex trading site is called local variables, its scope of action forextradingwebsiteonline only be accessed within the function that defines it, the code outside the function, can not access the variables inside the function For example: intfuncname(inta){intabc;//the variables inside the function, can only be accessed by the code inside the function. function outside can not access the variable abc;}2 function parameters: function parameters of each variable name can not function internal variable renamed parameters can also specify the default forextradingbrokerwebsite, for example: voidfunc(intx,doubley=0.0,boolz=true){...} This function specifies the default value of y for 0.0, the value of z for true call this function, you can not specify the default value of parameters such as func(9), then the equivalent of func(9,0.0,true) so called if called func(9,1.5) is equivalent to call the func(9,1.5,true). In general, the function parameters are passed values inside the function to change the value of the parameters, will not change to call the function of the block even if the array is also passed values into it then how do we pass references? By passing a reference, if the value of the parameter inside the function changes, the value of the variable corresponding to the segment calling the function will follow the change If you want to pass a reference, you need to add the symbol & after the function parameter type, such as: voidfunc(int&x,double&y,double&z[]){x=8;}One point Note: If you pass the function parameters by reference, you cannot pre-set the default value of the parameter parameters cannot exceed 64.3 Global variables: global variables are variables of the same level as the function, and its scope is the whole MQL code, which means that the global variables can be accessed in all places of the whole MQL such as: inta=10;intfunca(){Print(a);//can access to the global variable areturn(0);}intfuncb(){Print(a);//access to the global variable areturn(1);}4 External variables: If a variable is defined as an external variable, the EA client can set the value of this external variable e.g.: externinta=10;externcolorc= red;