Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy pnl

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

    strategy pnl

    hello,

    I need to keep track of the pnl a strategy has accumulated since it was last started. I need to keep track of the realized pnl + open PNL since the strategy was last enabled and stop trading if I go beyond a certain profit or loss. Hope this makes sense.

    Can you provide guidance on which api's to use for that.

    Onn

    #2
    Onn, there's no direct method we could hint at here, since technically the values are not persisted across different runs of the instances (enable / disable cycles). You can look for example into saving the realtime pnl for example to a text file - http://www.ninjatrader.com/support/f...ead.php?t=3477

    Comment


      #3
      by not persisted you mean that when a strategy goes through the enable/disable cycle, the internal vairables - private simple types (int, double, etc) and the complex types (DataSeries, classes, etc.) all get reset to initialized values?

      Is there a method I could override to catch the enable/disable?

      The example you sent saves the daily OHLC - is there another example that saves the realtime pnl?

      Comment


        #4
        Hello,
        Originally posted by onnb1 View Post
        by not persisted you mean that when a strategy goes through the enable/disable cycle, the internal vairables - private simple types (int, double, etc) and the complex types (DataSeries, classes, etc.) all get reset to initialized values?
        Each time you disable/enable the strategy the instance is removed or a new one is created. The values from the previous will not be stored internally and you would need to use an external file if you wish to track these values.

        Is there a method I could override to catch the enable/disable?
        Not exactly but potentially you could look into OnStartUp() and OnTermination()



        The example you sent saves the daily OHLC - is there another example that saves the realtime pnl?
        The following is an example of using performance statistics to regulate trading: http://www.ninjatrader.com/support/f...ead.php?t=4084

        For more on these in the help guide: http://www.ninjatrader.com/support/h...erformance.htm
        LanceNinjaTrader Customer Service

        Comment


          #5
          thanks. this helps a lot.

          I'm almost there. I have a strategy and I am using pnl for some of the logic. If I want the code to run in a backtest and I want it to also run in realtime, but in realtime I only want the realtime trades to be counted for, how do I do that?

          Would I be using Performance.AllTrades and have in my code

          if (Historical)
          {
          return;
          }

          Because, if I am using Perforamance.Realtime, that won't work in a backtest - at least that is what I am seeing.

          Comment


            #6
            Hello,

            You would have to either manually change from Realtime/AllTrades/Historical as needed or you could use user input to change the settings on the fly.

            There are a couple ways you could set up your if statements to handle this.

            Based on what you already have you could do something like

            Code:
            private bool isNotABacktest; //would need to set this up to take in user input
            ...
            
            if(Historical && IsNotABacktest)
                return;
            Let me know if I can be of further assistance.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            670 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            379 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            111 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            575 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            582 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X