Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Update a file with running PnL

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

    Update a file with running PnL


    I created a separate strategy that is nothing but account update.
    I write to a file the current Pnl as it changes. So I have a strategy but I guess it could be an indicator. I want to record a certain account with the pnl. I have everything for creating the file. Thats all working, But I would rather just update when PnL changed.
    I get a file updated but there is no current Pnl from the account the strategy is added to. When I add the strategy for account update it , the account already has a current PnL but it shows 0 in the file that's getting updated. So what is proper code to get the current account info?
    Here is the code snippet:
    protected override void OnBarUpdate()
    {
    PnLUpdate();
    }

    private void PnLUpdate()
    {
    PnL_unrealized = Math.Round(Position.GetUnrealizedProfitLoss(Perfor manceUnit.Currency),2);
    PnL_realized = Math.Round(SystemPerformance.RealTimeTrades.Trades Performance.Currency.CumProfit,2);
    accountDetails = PnL_unrealized.ToString("N2") + ";" + PnL_realized.ToString("N2") + ";" + DailyProfitLimit.ToString("N2") + ";" + DailyLossLimit.ToString("N2");
    File.WriteAllText(path,accountDetails);

    }

    #2
    Hello set2win,

    Thank you for your note.

    To get the overall PnL for the account, you'll need to use add-on code in an indicator or strategy to get the overall account PnL - what you're trying above would only give you a strategy's calculated PnL, not the PnL of the account.



    I've created a basic example that subscribes to a chosen account, gets the current realized PnL and writes the realized and any unrealized PnL to a file based on receiving AccountItem updates that should be of help.

    Please let us know if we may be of further assistance to you.
    Attached Files

    Comment


      #3
      Perfect that should do it for me, I kind of thought that the way I had it was designed to work within an actual strategy that was active making trades. Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      58 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      133 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      73 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X