Position Sizing scripts are used for overriding the quantity of pending orders after those were generated by a Trading Strategy script. Common use-cases include testing the impact of various position sizing methods on a trading strategy's performance, as well as sharing sophisticated position sizing logic between strategies. Using Position Sizing scripts is completely optional as Trading Strategy scripts already assign quantity to all of their orders.


Setup


A Position Sizing script can be set up from the Desktop Strategy Wizard when a new strategy is added to a Desktop.


Functions


Name

Description

OnInitialize()

This function is used for accepting the script parameters and for initializing the script prior to all other function calls. Once the script is assigned to a Desktop strategy, its parameter values can be specified by the user and can be selected for optimization.

double OnPositionSize(int, int)

This function is called for each pending order. It should examine the specified order and return the number of shares, contracts or units to assign it.

OnShutdown()

This function is called when the script is shutdown.


Function Details


OnInitialize()

This function is used for accepting the script parameters and for initializing the script prior to all other function calls. Once the script is assigned to a Desktop strategy, its parameter values can be specified by the user and can be selected for optimization.


double OnPositionSize(int symbolIndex, int orderIndex)

This function is called for each pending order. It should examine the specified order and return the number of shares, contracts or units to assign it.


Returns


The number of shares, contracts or units to assign the specified order.


Parameters


Type

Identifier

Description

int

symbolIndex

The index of the symbol in the strategy symbol table

int

orderIndex

The order index to which a size should be assigned


OnShutdown()

This function is called when the script is shutdown.