Variable (Reserved Word) same as Var, Vars, Variables
The reserved word Variable (or Var, Vars, Variables) is used to specify the name of a user-declared variable, its initial value, and optional data type. This must be done before a user-declared variable can be used in an assign statement or formula. Multiple variables' names may be declared using a single Variable statement where the names are separated by commas.
Syntax-Common
Variable: Name(Value) ;
Where Name is the unique name of the user-declared variable, and Value is either a Numeric, True/False, String, or Null value used as the initial value of the variable. The common form of the variable declaration statement appears in the main body of an EasyLanguage document and requires that an initial value be included in parentheses following the name.
The variable declaration syntax for the main body of an EasyLanguage document are slightly different than for a variable declaration in a local method (see below). In the main body declaration, an initial value is required after the variables name and any data type is optional.
Syntax-Complete
Variable: <IntraBarPersist> <DataType> VarName(InitialValue<,datan>)<, <IntraBarPersist> <DataType> VarName(InitialValue<,datan>)> ;
-
Variable is the variable declaration statement that may alternately be typed as Var, Vars or Variables.
-
IntraBarPersist indicates that a variables value can be updated on every tick. By default, variable values are only updated at the close of each bar.
-
DataType is the optionally supplied data type (float, double, int, bool, string, or class) of the variable, typically used to conserve memory.
-
VarName is the user specified variable name. Variable names may include alphanumeric characters, underscores (_), periods (.), dollar signs ($), the "at" symbol (@), and the pound sign (#).
-
InitialValue is the initial value of the variable.
-
DataN is an optional parameter that identifies the data stream the variable is tied to and may be data1 through data50.
Syntax-Method
Variable: DataType Name ;
Where Name is the unique name of the user-declared variable, and DataType defines the type of value (float, double, int, bool, string, or class) that may be assigned to the variable.
The variable declaration rules in a local method are slightly different than for a variable declaration in the main body of an EasyLanguage document (see above). In a method, the data type is required and no initial value is allowed after the variables name.
Remarks
A variable name can contain up to 20 alphanumeric characters plus the period ( . ) and the underscore ( _ ).
A variable name can not start with a number or a period ( . ).
The default value of a variable is declared by a number in parenthesis after the input name.
Multiple variables names may be declared using a single Variable statement where the names are separated by commas.
The use of the reserved words Variable,Var, Vars, and Variables is identical.
Examples
Variable: Count(10);
declares the variable Count and initializes the value to ten.
Var: MADiff(0), MyAverage(0);
declares the variables MADiff and MyAverage and initializes their values to zero.