Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Kate W.NinjaTrader Customer Service

    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 burtoninlondon, Today, 12:38 AM
      0 responses
      5 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      12 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Working...
      X