Instrument Context:

Trading Blox Builder makes access to instrument data simple.  All information specific to each symbol is contained in an Instrument Object.  This object's properties and functions is how instrument information is accessed and changed.  Each instrument's information pertains to only that symbol.   Reference to other information like orders and positions will use the instrument symbol in recording that information.

 

Access to an Instrument is available from any script.  Script sections that provide direct instrument access are the script section with automatically instrument context.  Context for instruments means the software conditions required for access any instrument are in place.  When the context is automatic, the user can use the instrument object's functions and properties with out the need to provide the required context conditions.  When the context is not automatically provided, the user has to create the instrument object's access requirements by manually creating the required context conditions.  Click LoadSymbol for more information.

 

These script sections get get automatic instrument context.  Click Blox Script Timing to get more information about when these scripts sections are available.

Script Section Names with Automatic Instrument Context

Rank Instrument

Can Fill Order

Filter Portfolio

Exit Order Filled

Before Instrument Day

After Instrument Open

Exit Orders

Adjust Stops

Entry Orders

Compute Instrument Risk

Unit Size

Adjust Instrument Risk

Can Add Unit

After Instrument Day

Update Indicators

 

 

Can a blox know when a script section has automatic instrument context?

Yes.  Trading Blox Builder Basic property block.instrumentExists will return a True when executed in a script section does have automatic instrument-context, and a False when instrument-context needs the LoadSymbol() function to make an instrument's information available.

 

Script sections that do not automatically provide instrument context will always need the LoadSymbol() function when multiple instruments are looped into the same BPV Instrument variable name.  This LoadSymbol()function loads the selected symbol's information as a bi-directional connection that allows access to the data for a symbol, and allows the use of functions that will change any IPV instrument information that were created for the instrument is being accessed.  

 

Does automatic instrument-context allow access to IPV variables?

Yes.   Any data specific to a symbol is available once the instrument-context has been established.  This is happens when a script section get automatic-context, and it is available when an instrument is assigned to a BPV instrument type using the LoadSymbol()function.

 

Click LoadSymbol for more information.

BPV Instrument-Context Variable Example:

Click to Enlarge; Click to Reduce.

BPV Instrument Variable Type

This BPV Instrument Type and LoadSymbol() function can used with any symbol that is available.  It can also be used to access information in another system that is in the same test suite.   Access to instruments in other systems in the same suite requires the test.SetAlternateSystem(systemIndex) example.

 

When a BPV Instrument Type variable is used to load an instrument's information, that name can be used elsewhere in the module to reference the values of the last loaded instrument.  In some cases a series of BPV - Instrument types are created with recognizable names so they can each load a different instrument and provide simple access to that instrument's information whether it is in context or not where it is needed.

 


 

When an instrument doesn't get automatic context, or an additional instrument is needed in script were it is provided (think spreads), this example can be used to make an additional symbol accessible.

Example:

'  In a script with Automatic-Context, this is how
'  the date of the instrument record is obtained.
variable1 = instrument.date
 
'  In a script section where Automatic Instrument-Context is Not
'  provided, this is how an instrument's record date is obtained
 
'  Create a BPV Instrument Type name that will accept an instrument's
'  information (See BPV Dialog Above).
 
'  Call LoadSymbol with a instrument's reference.  
'  Next example is using the instrument's symbol.
'  There are more ways for LoadSymbol to bring an
'  instrument into context and so the instrument's
'  information can be assigned.

 
'  Set the portfolio instrument.
aBpvName.LoadSymbol( "GC" )

 
'  Pass the instrument's date to another variable
anyDate = aBpvName.date
 

 

Scripts with automatic instrument context will execute the same script name for each of the instruments in the portfolio.  This repetitive loop of each instrument is necessary so that all the symbols in the portfolio have a chance to be processed on each test date.  Click this topic Comprehensive Simulation Loop for more information about the testing process actions.

 

When an instrument doesn't have a data current date the next market date, the instrument record that will be processed with the previous record in the data file.  When an instrument does not have a current date for the next market date, the instrument.tradesOnTradeBar property will return a False value so scripting can prevent a calculation from counting a previous record more than once.  When there is a current date for the next market date, the return is True.

 

Instrument Priming:

When indicators are contained in a system, the parameter with the largest calculation look-back value will determine when the system can be allowed to generate orders.  This means a system that is expected to generate orders by the Suite Start-Date will need information before that Start-Date so there no Start-Date trading delay.  

 

How much data is needed can be calculated, but the value must be the enough for all the calculations in the system to have begun their calculations prior to the planned Start-Date.

 

Trading Blox helps to make this possible by examining the parameters in the system that have enabled the parameter’s Look-Back option.  

Parameter_Lookback_Option

When this option is enabled, Trading Blox Builder will use all the available data ahead of the Start-Date so that the calculations will be primed and ready for the system.

 

Providing data to be available for calculation is controlled by the user’s “Years of Priming” setting in the Data Folders and Options section of the Trading Blox Builder Preference setting dialog:

Years-of-Priming Preference Setting

By default, this setting is set at “5” years of information.  This means that <TB> will attempt to load up to five-years of trade records of available records for each of the instruments in system’s portfolio.  This extra-data value allows the system to begin calculation ahead of the Start-Date.  Trading Blox Builder will begin the system's calculation at the earliest possible time so the system can prime all of the instrument's calculated information to be ready to generate signals by the Start-Date.  

 

Some instruments in the portfolio may not have enough trading information ahead of the Start-Date.  When the system encounters this condition, any instrument that hasn't primed its calculation will not be allowed to trade until its data is primed.

 

<in process>

 


 

System Testing Sequencing:

When a test is started, Trading Blox Builder creates a list of all the trade day dates that from the start, usually this means just the weekday dates dates when

 


 

Instrument Looping:

<in process>

 

Automatic Order Context Access:

Order object properties and functions are available in the Unit Size, Can Add Unit, and Can Fill Order script section where they get object context by default. They are also in context in the Entry Orders, and Exit Orders script section after a Broker function statement when the Broker initiated order has not been rejected.

 

An order is available when the system.orderExists () property returns a TRUE result after a Broker function statement returns execution from Unit Size and Can Add Unit script sections to the Entry Orders or Exit Orders script section.  

 

Note:

Orders are also in context in the Entry Orders Filled and Exit Orders Filled script section when those orders have been filled.

 

In all other script sections where an order does not have context, access to an order property or order function is possible when the AlternateOrder object process is used to bring the order object into context.  Order object must be in context by default or my using the AlternateOrder function.  When it is in context active order property information and functions can be accessed or executed to make changes.  

 

Do Not use the Order object in any of the script sections where it does not get automatic object context by default.

 


Edit Time: 9/25/2017 09:09:58 AM


Topic ID#: 112

 

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