When you want to access one or more of the portfolio's instruments to read an instrument property, execution an instrument function or access one of the indicators associated with an indicators, this is possible using the BPV Variable Type Instrument.
BPV instruments can access and instrument in the portfolio, or they can emulate a specific instrument so that they can be easily accessible anywhere in the system without regard for script section's instrument context normal state.
To get access to a specific IPV instrument the target instrument must first be brought into context using Instrument Object's LoadSymbol function. This function will accept a portfolio index number in the range of 1 to the total number of instruments in the portfolio, or it will accept an instrument's symbol.
Naming the BPV instrument variable can be any name like "portfolioInstrument" as a replacement object name. This replacement of the instrument object name will make it easier to understand, and it will be available to use in scripts that have a automatic instrument context, and in scripts that don't support automatic instrument context.
A specific name like "SPX_I," "Corn," "Gold" and other names can be used. Specific names for an individual symbol reports the information contained is for only the symbol identified. When batch processing of instruments is needed, use a generic name. When a specific instrument needs to be available throughout the testing, use a specific name to make script coding more understandable.
More details are available here: LoadSymbol
Example: |
---|
Accessing instruments out of their normal context scripts requires the use of a Instrument container class variable, which is shown in this BPV dialog: Any name can be used for the container variable. When accessing any IPV out of context, the variable name must be used in the prefix or object name location. In the code script shown below, the symbol is accessed by using the variable name and the instrument property for the symbol, which is symbol -- portfolioInstrument.symbol |
Example: |
---|
' Local declared variables VARIABLES: instrumentCount, x Type: Integer |
In this code section the script is using the System's totalInstruments property. This property contains the total number of symbols listed in the portfolio so the For loop structure would know how many times it should loop to get access to all the portfolio's instruments.
When the above is executed with the Canadian Dollar, Euro, Feeder Cattle and Corn in the portfolio, the main screen's Log Window will show this information:
Returns: |
---|
1 - Portfolio contains: CD 2 - Portfolio contains: EC 3 - Portfolio contains: FC 4 - Portfolio contains: C2 |
Links: |
---|
See Also: |
|
Edit Time: 9/21/2020 3:33:27 PM |
Topic ID#: 113 |