|
VARIABLES Declaration |
Top Previous Next |
|
Variables declared using the VARIABLES statement are only useable in the script in which they are declared. You cannot, for instance, define a variable in the entry script and then use it in the exit script. Use a permanent variable or parameter if you want a variable that is useable by more than one script.
Variables declared with the VARIABLES statement are undefined every time a script is run, so they should be set to a known value at the top of the script before being used. Therefore, it is sometimes faster to use a Block Permanent Variable or Instrument Permanent Variable, especially if you are using large amounts of data.
Syntax
VARIABLES: varname1 [TYPE: type ], varname2 [TYPE: type ] ...
varname Name of the variable. type Type of the variable.
The following examples illustrate the use of the VARIABLES statement:
VARIABLES: someValue TYPE: Integer ' someValue was defined and can be only integer
someValue = 10 ' someValue is integer and contains 10 someValue = 3.15 ' someValue is integer and contains 3
VARIABLES: a TYPE: Floating ' Single VARIABLES statement
VARIABLES: a, b, c TYPE: Integer ' Three variables in single VARIABLE statement
VARIABLES: str1 TYPE: String, int1 TYPE: Integer ' Multiple variables of different types
A VARIABLES statement can define variables of any of the following types:
The variable someValue should be a Price in the following situations: someValue = instrument.close someValue = instrument.high - averageTrueRange someValue = instrument.low * 1.2 someValue = longMovingAverage (where longMovingAverage is a moving average indicator)
The variable someValue should be a Floating type in the following situations: someValue = instrument.close - instrument.close[1] someValue = instrument.high - instrument.low someValue = averageTrueRange |