Slippage scripts are used for simulating market slippage by setting the final execution price of each simulated order fill. Common use-cases include testing the impact of various market conditions on a trading strategy's performance and manipulating the final execution price of each order fill.


Setup


A Slippage script can be set up from the Advanced tab in the Desktop Settings.


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, its parameter values can be specified by the user and can be selected for optimization.

double OnOrderFillSlippage(int, int, int, double, double)

This function is called on each new order fill in order to calculate its slippage.

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, its parameter values can be specified by the user and can be selected for optimization.


double OnOrderFillSlippage(int strategyNumber, int orderIndex, int orderFillIndex, double fillQuantity, double fillPrice)

This function is called on each new order fill in order to calculate its slippage.


Returns


The price of the order fill after slippage (return the specified price if there was no slippage).


Parameters


Type

Identifier

Description

int

strategyNumber

The Desktop strategy number to which the order belongs

int

orderIndex

The order index in the orders table to which the order fill belongs

int

orderFillIndex

The order fill index (0 being the first fill for the order, 1 being the next fill, etc.)

double

fillQuantity

The quantity of the new order fill for the specified order

double

fillPrice

The price of the new order fill for the specified order


OnShutdown()

This function is called when the script is shutdown.