Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Printing Total PnL to Output Window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Printing Total PnL to Output Window

    I am trying to print to output window 2 my current unrealized and total PnL (the same values you would see in the control center window) on every tick change.

    The unrealized works fine but the total PnL ("Realized" in my string) is always zero. What am I missing here!?



    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;
    PrintTo = PrintTo.OutputTab2;
    Print(DateTime.Now.TimeOfDay + @";Unrealized:;" + PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Currency, Close[0]) + @";Realized:;" + SystemPerformance.RealTimeTrades.TradesPerformance .Currency.CumProfit);
    }



    Section of ; delimited output (How can I reduce the currency output to 2 decimals?) :
    Also, why would I have multiple entries at the same millisecond?


    ​10:17:47.3780117;Unrealized:;912.499999999955;Rea lized:;0
    10:17:47.3780117;Unrealized:;912.499999999955;Real ized:;0
    10:17:47.3780117;Unrealized:;912.499999999955;Real ized:;0
    10:17:47.3780117;Unrealized:;912.499999999955;Real ized:;0
    10:17:47.5570091;Unrealized:;949.999999999955;Real ized:;0
    10:17:47.5570091;Unrealized:;949.999999999955;Real ized:;0
    10:17:47.7019667;Unrealized:;912.499999999955;Real ized:;0
    10:17:47.7690275;Unrealized:;912.499999999955;Real ized:;0
    10:17:47.7690275;Unrealized:;949.999999999955;Real ized:;0​

    #2
    Hello tyler_cooney85,

    You can format the string to reduce the number of places.

    string unrealizedpnl = PositionAccount.GetUnrealizedProfitLoss(Performanc eUnit.Currency, Close[0]).ToString("N2");
    string realizedpnl = SystemPerformance.RealTimeTrades.TradesPerformance .Currency.CumProfit).ToString("N2");

    Print(DateTime.Now.TimeOfDay + @";Unrealized:;" + unrealizedpnl+ @";Realized:;" + realizedpnl);

    Keep in mind you are mixing the account position pnl and the strategies individual pnl in the code you provided. If you intended to get the strategies unrealized it should be Position instead of PositionAccount. The strategy had 0 PnL when this was called so it has 0 realized pnl. If you are running other strategies it won't get the realized PnL from that method for the account.

    regarding the timestamps you can see multiple ticks come in at the same time so you can have shared timestamps for tick events.
    Last edited by NinjaTrader_Jesse; 03-28-2025, 10:41 AM.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    78 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X