Accessing System Portfolio Instruments

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

A generic name like "portfolioInstrument" is generic and denotes it is used for loading more than one instrument.  A specific name like "SPX_I" implies 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



Accessing instruments out of their normal context scripts requires the use of a Instrument container class variable, which is shown in this BPV dialog:

BPV_Dialog Instrument Type-2

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



'  Local declared variables

VARIABLES: instrumentCount, x Type: Integer
' Get the instrument count.
instrumentCount = system.totalInstruments
' Loop printing the symbol for each instrument.
For x = 1 TO instrumentCount STEP 1
  ' Set the portfolio instrument.
  portfolioInstrument.LoadSymbol( x )
  ' Print out the file name.
  If portfolioInstrument.inPortfolio THEN
    PRINT x,". Portfolio contains: ", portfolioInstrument.symbol
Next ' x


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:


1 - Portfolio contains:  CD

2 - Portfolio contains:  EC

3 - Portfolio contains:  FC

4 - Portfolio contains:  C2



Instrument Loading, System Properties,

See Also:



Edit Time: 4/6/2017 02:16:44 PM

Topic ID#: 113


Created with Help & Manual 7 and styled with Premium Pack Version 2.80 © by EC Software