These variables can be different for each instrument, but retain their value (unlike variables declared with the VARIABLES statement). For instance, totalProfit (shown below) can be 100 for Soybeans and 50 for Gold.
To create a Instrument Permanent Variable, select "Instrument Permanent Variables" on the left and click the "New" button.
The Name for Code is the name of variable as you would use it in a Script. Common convention is that you start variable names with a lower case, and use upper case for the first letter of each subsequent word or part of the variable name. No spaces or special characters are allowed in variable names.
The Name for Humans is a more friendly description of the variable. In the case of Instrument Permanent this name is not displayed anywhere unless the variable is a series, but is useful to remember what the variables purpose is. For series variables, the Name for Humans is used as the label.
Defined Externally in Another Block -- check this option if this variable has been declared as System Scope in another block in the system. This option lets the Syntax Checker know about this variable.
The Variable Type is the kind of value the variable will be, and cannot be changed in a script. For a description of the different types, see the VARIABLES section.
An IPV of type Series String can be used to display a different string value for each bar on the trade chart. It will not plot of course.
The Default Value is the value that will be assigned to the variable when it is first used. So in this case at the start of running the program, the variable lastMonth will be set to 0.
Upon creation, you can now use this variable in any of the Scripts of the Block using the variable name "lastMonth."
The Scope determines where you can use this variable. Instrument Permanent Variables cannot be Test scope.
•Block -- You can only use this variable in the scripts that are in the block.
•System -- You can use this variable in any block in the System by declaring the variable as External in the other blocks.
•Simulation -- Same as System scoped except the value is not reset for every test (parameter run).
Note that for Instrument Permanent Variables, if you select the Series variable type, you have the option to plot. If you want to plot the value, it is recommended to use the Auto Index feature. The Auto Index will set the index using the instrument.bar property.
As with Indicators, select Plots on Trade Chart, Displays on Trade Chart, Select the color, set the Graph Area, Select Offset by One Day if desired. The Graph Style has many options. Use the one most appropriate to your situation.
For both Block Permanent and Instrument Permanent, if you do not select Auto Index, you must specify a size for the array. This example, curentStopPrice, is an Auto Index series that plots in the Price Chart graph area in Red as Small Dots.
You can access Instrument Permanent Variables through scripting two ways.
1.Using the variable directly. This will return the variable for the current instrument:
myInstrumentVariable = 5
IF myInstrumentVariable = 5 THEN PRINT "It is 5"
If a Series object you can access and set the index values:
mySeriesVariable = 5
IF mySeriesVariable = 5 THEN PRINT "Yesterday was 5"
2.Or you can access instrument variables using the instrument or another instrument variable object as follows:
instrument.myInstrumentVariable = 5
sp500Index.myInstrumentVariable = 5
sp500Index.mySeriesVariable = 5
IF instrument.myInstrumentVariable = 5 THEN PRINT "S&P has 5"
IF sp500Index.mySeriesVariable = 5 THEN PRINT "S&P has 5"
Accessing a variable using the instrument '.' syntax is equivalent to using the variable directly. The '.' syntax is the only way to access the value of instrument variables which are not part of the current instrument.
Edit Time: 9/25/2017 09:09:54 AM
Topic ID#: 320