GetUnrealizedProfitLoss()

<< Click to Display Table of Contents >>

Navigation:  NinjaScript > Language Reference > Strategy > PositionAccount >

GetUnrealizedProfitLoss()

Previous page Return to chapter overview Next page

Definition

Calculates the unrealized PnL for the account position.

 

Method Return Value

A double value representing the account's unrealized PnL.

 

Syntax

PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit unit, double price)

 

Note: If no double argument is provided, double.MinValue will be used.

 

 

Parameters

unit

Possible values:
PerformanceUnit.Currency

PerformanceUnit.Percent

PerformanceUnit.Pips

PerformanceUnit.Points

PerformanceUnit.Ticks

price

Price used to calculate the PnL such as Close[0]. This value is used as the current price and compared against your entry price for the PnL.

 

 

Examples

ns

protected override void OnBarUpdate()
{
    // If not flat print our unrealized PnL
    if (PositionAccount.MarketPosition != MarketPosition.Flat)
        Print("Open PnL: " + PositionAccount.GetUnrealizedProfitLoss(PerformanceUnit.Points, Close[0]));
}