TYPE:

Description:

Instrument - BPV

Direct access to instruments is only available in the scripts that allow the instrument object context.  To access an instrument in a script where it doesn't have context it is necessary to use this BPV type so an instrument can be moved into context and made accessible.

 

Notes:

Data instrument access to its properties and functions is automatic when the instrument has context, and when the symbol is active in a script where instruments have context.  Context means the information is automatically made available when that script section is executing and the portfolio looping brings that instrument into the script.  

 

When other script sections are executing, Trading Blox doesn't loop instruments, but instead will on execute scripts without instrument context once for each bar being tested.  To access an instrument the script will need to bring the instrument into context in order to gain access to its properties and functions.  To bring an instrument into context, use a BPV Type Instrument variable as the structure where the instruments data can be copied so it can be accessed.

 

This table is a current list of the script section that automatically bring instruments into context automatically, and the scripts sections where scripting code will be required to gain access to an instrument:

Script Instrument Access

Automatic Access:

Manual Access:

Rank Instruments

Filter Portfolio

Before Instrument Day

Exit Orders

Entry Orders

Unit Size

Can Add Unit

After Instrument Open

Update Indicators

Can Fill Order

Entry Order Filled

Can Fill Order

Exit Order Filled

Adjust Stops

Adjust Instrument Risk

After Instrument Day

Before Simulation

Before Test

Before Trading Day

Before Bar

Before Order Execution

After Bar

Initialize Risk Management

Compute Risk Adjustments

After Trading Day

After Test

After Simulation

 

 

When access to instrument information isn't automatic it can be loaded into the BPV Instrument Variable Type using the LoadSymbol function.  This next example shows how all of the instruments in the portfolio can be loaded and accessed:

Example:

'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Example of how to bring instruments into context
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  When Portfolio has selected instruments,...
If System.TotalInstruments > 0 Then
  '  Loop through all the instruments in the portfolio
  For x = 1 to System.TotalInstruments Step 1
    '  Load instrument at portfolio's index position of ' x '
    '  and place the information into the BPV instrument ' Mkt '
    '  When function executes, it will assign a 1 if the
    '  instrument access is successful, or a 0 when access fails
     iLoadOK = Mkt.LoadSymbol( x )
     
    '  if iLoadOK is TRUE ( greater than 1 )
    If iLoadOK Then
        '  Display the instruments symbol in the Log Window
        Print "Mkt.Symbol       ", Mkt.Symbol
    EndIf
  Next '  x
EndIf '  System.TotalInstruments > 0

Returns:

Mkt.Symbol        CL2

 

 

In the above example a generic name of 'Mkt' was assigned to the BPV instrument.  When an instrument access needs to be available through out a simulation, a unique name can be given to a BPV instrument so it canceled using that unique name and thus be available without having to bring it into context with a loading script.  Consider this simple Grain market example:

Example:

'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Load three grain instruments into grain named BPV Instruments.
'  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Load Corn into BPV Instrument Corn
If Corn.LoadSymbol( "C2" ) = TRUE THEN Print "Corn Market Loaded"
 
'  Load Soybeans into BPV Instrument Soybeans
If Soybeans.LoadSymbol( "S2" ) = TRUE THEN Print "Soybean Market Loaded"
 
'  Load Wheat into BPV Instrument Wheat
If Wheat.LoadSymbol( "W" ) = TRUE THEN Print "Wheat Market Loaded"

 

Returns:

Corn Market Loaded

Soybean Market Loaded

Wheat Market Loaded

 

 

In the above example each of the grain markets can be called in any of the script sections without having to load them where they are not normally in the context of that script.  Calling them in any of the scripts would look something like this:

Example:

'  Script line using BPV Instrument Corn placed in each of

'  Blox script sections so that each could report what it

'  found accessible.
Print Block.ScriptName, Corn.Symbol, Corn.Date, Corn.Close

 

Returns:

'  Details shown are text copies of some of the
'  data records generated by the above when it
'  was placed in each of the script section in
'  the blox

Before Test C2 2007-12-27 508.250000000

Update Indicators C2 2007-12-27 508.250000000

Before Trading Day C2 2007-12-27 508.250000000

Before Instrument Day C2 2007-12-27 508.250000000

Update Indicators C2 2007-12-28 505.500000000

After Instrument Day C2 2007-12-28 505.500000000

After Trading Day C2 2007-12-28 505.500000000

Before Trading Day C2 2007-12-28 505.500000000

Update Indicators C2 2007-12-31 509.000000000

After Instrument Day C2 2007-12-31 509.000000000

After Trading Day C2 2007-12-31 509.000000000

After Test C2 2007-12-31 509.000000000

After Simulation C2 2007-12-31 509.000000000

 

 


 

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