Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to reset a SystemPerformance Collection variable every day

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

    How to reset a SystemPerformance Collection variable every day

    Hello,

    My strategy requires to constantly monitor SystemPerformance.WinningTrades/LosingTrades throughout the day. I realize that these values are carried over to the next day but I need them to reset at the beginning of each day.

    Is it possible to reset these types of values or do I need to create a counter for my winning and losing trades and reset those values?

    #2
    Hello Don22Trader1,

    The SystemPerformance cannot be reset and will contain all trades made by the strategy instance.

    You would need to save the trades to your own collection if you are wanting to reset this.

    Possibly a List<Trade> collection could be used.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I tried to create a counter that will reset like this:

      protected override void OnBarUpdate()
      {

      if (Bars.IsFirstBarOfSession && IsFirstTickOfBar)
      {
      WinsCounter = 0;
      }

      Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];

      if (lastTrade.ProfitCurrency > 0)
      {
      WinsCounter++;
      }
      }

      since i've applied this, the strategy will not run on a backtest and i recieve this error
      "Error on calling 'OnBarUpdate' method on bar 691: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart"

      i dont understand how to get around this.

      Comment


        #4
        Hello Don22Trader1,

        With any index used this will need to be larger than the collection.

        Below is a link to a forum post on index errors.
        Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


        The last trade cannot be found until there is at least 1 trade.

        So SystemPerformance.AllTrades.Count must be greater than 0.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello Don22Trader1,

          The SystemPerformance cannot be reset and will contain all trades made by the strategy instance.

          You would need to save the trades to your own collection if you are wanting to reset this.

          Possibly a List<Trade> collection could be used.
          Where do you initialize that list?

          ///Class Variable
          List<Trade> myTrades;

          /// else if (State == State.Configure)​ ?
          {
          myTrades= new List<Trade>();
          }

          Comment


            #6
            Hello PaulMohn,

            Yes, similar to a custom Series. You could also create a custom Trade series (Series<Trade>).

            Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.

            Comment

            Latest Posts

            Collapse

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