OnPositionUpdate()
OnPositionUpdate()
Definition
An event driven method which is called each time a PositionUpdate is received for the strategy.
- This method is typically called after OnExecutionUpdate().
- OnPositionUpdate() will update with PositionUpdates that are filtered for the strategy. The strategy Position object is driven by Executions, and is updated as early as OnExecutionUpdate().
- You will NOT receive position updates for manually placed orders, or orders managed by other strategies (including any ATM strategies) in OnPositionUpdate(). The Account class contains a pre-built event handler (PositionUpdate) which can be used to filter position updates on a specified account.
- It’s best practice to only work with the passed by value parameters and not reference parameters. This insures that you process each change of the underlying state.
- Rithmic and Interactive Brokers Users: When using a NinjaScript strategy it is best practice to only work with passed by value data from OnExecution. Instances of multiple fills at the same time for the same instrument might result in an incorrect OnPositionUpdate, as sequence of events are not guaranteed due to provider API design. For an example on protecting positions with this approach, see OnExecutionUpdate().
Method Return Value
This method does not return a value.
Syntax
You must override the method in your strategy with the following syntax:
protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
Method Parameters
Possible values are:
- MarketPosition.Flat
- MarketPosition.Long
- MarketPosition.Short
Examples
Understanding the order object parameter vs updating value parameter (Multi-Thread Considerations for NinjaScript)
Additional Reference Samples
Additional reference code samples are available in the NinjaScript Educational Resources section.

