Risk Management scripts are used for managing risk by modifying or cancelling trading strategy orders based on portfolio level risk analysis. Common use-cases include managing risk during extreme market conditions and limiting overexposure to a single symbol due to multiple trading strategies that are trading it.


Setup


A Risk Management 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.

OnRiskManagement(int, int)

This function is called once for each new pending order before it's submitted to the broker, so that it may modify or cancel it if necessary.

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.


OnRiskManagement(int strategyNumber, int orderIndex)

This function is called once for each new pending order before it's submitted to the broker, so that it may modify or cancel it if necessary.


Parameters


Type

Identifier

Description

int

strategyNumber

The strategy number to which the order belongs

int

orderIndex

The order index in the orders table


OnShutdown()

This function is called when the script is shutdown.