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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    75 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    152 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    162 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    100 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    289 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X