OnPositionUpdate()
<< Click to Display Table of Contents >> OnPositionUpdate() |
An event driven method which is called each time the position of a strategy changes state.
•This method is typically called after OnExecutionUpdate()
•OnPositionUpdate() is called for every change in strategy position
Notes:
•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. •Its 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: Due to provider API design these adapters do not guarantee the sequence of events of OnOrderUpdate, OnExecution, and OnPositionUpdate. Therefore when working on a strategy that will run on these connections it is best practice to only work with passed by value data from that callback to eliminate the dependency on the sequence of events. |
This method does not return a value.
protected override void OnPositionUpdate(Position position, double averagePrice, int quantity, MarketPosition marketPosition)
{
}
position |
A Position object passed by reference representing the current position object |
averageFillPrice |
A double value representing the updating average fill price of a position |
quantity |
An int value representing the updating quantity of a position |
marketPosition |
A MarketPosition object representing the updating position update provided directly from the broker.
Possible values are:
•MarketPosition.Flat •MarketPosition.Long •MarketPosition.Short |
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, |
Understanding the order object parameter vs updating value parameter (Multi-Thread Considerations for NinjaScript) |
|
---|---|
protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, |
Additional Reference Samples
Additional reference code samples are available the NinjaScript Educational Resources section of our support forum.