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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    110 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    59 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    37 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    41 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    78 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X