Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with DataSeries

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

    Help with DataSeries

    I am having trouble with getting the following to work. The major problem is the:
    // ighest value:
    double _highestcumprofit = MAX(mycumprofit, Bars.BarsSinceSession - 1)[0];

    It locks up Ninja.
    I have the following:
    #variables
    private DataSeries mycumprofit;

    #init
    mycumprofit = new DataSeries(this);

    #onbarupdate

    if (Bars.FirstBarOfSession)
    mycumprofit = new DataSeries(this); // re-init each day

    mycumprofit.Set(Performance.AllTrades.TradesPerformance.Currency.CumProfit);

    // then to get the highest value:
    double _highestcumprofit = MAX(mycumprofit, Bars.BarsSinceSession - 1)[0];

    // and to find out how many bars ago that was
    int _highestcumprofit_bar = HighestBar(mycumprofit, Bars.BarsSinceSession - 1);

    // and to find out the time stamp of that bar
    Print(Time[_highestcumprofit_bar] + ": this was the time I made " + _highestcumprofit.ToString());

    #2
    vast524, do you see any errors in the log tab when it 'locks' up? I'm not sure why you reinit the dataseries each day, just set a value of 0 if a new session starts...

    Comment


      #3
      Just runs out of system memory.
      It seems to have an issue with the MAX line.
      How do I set it to 0 rather than reinit at the start of the session? In the variables section?

      Comment


        #4
        You can just set to a value of 0 at the session begin -

        Code:
         
        if (Bars.FirstBarOfSession)
        mySeries.Set(0);

        Comment


          #5
          Unfortunately it is still hanging.
          I can't can't check the log as Ninja is frozen.
          Is the script I am using the correct way of gaining the MAX value of the session?
          It seems to be this part of the script that is causing the trouble.
          I blank out this and the script loads.

          Comment


            #6
            I would not recommend doing it that way. You should instead just keep track of the highest profit the same time your strategy is trading. After it finishes a new trade, store cum profit to a variable. Check new cum profits versus previous cum profits. If it is higher then store the new value.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              So Josh, are you saying not to use a DataSeries then?

              Comment


                #8
                Right. No need to allocate full resources for a DataSeries when you are really only after one value.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  How do I store this curent value.
                  I guess I will need a variable like
                  private double MaxCumProfit = 0;
                  Then have in barupdate
                  double MaxCumProfit = (double) Math.Round(cumProfit + curPosition) ;

                  Comment


                    #10
                    What is the advantage or disadvantage of doing the following with the double:
                    double cumProfit = (double) Math.Round(Performance.RealtimeTrades.TradesPerfor mance.Currency.CumProfit);

                    I had copied it from another piece of code. Is it because it is placed in the OnBarUpdate section?

                    Comment


                      #11
                      Using doubles for this would generally reduce resources.

                      Comment


                        #12
                        Thanks for the help. Unfortunately I am still very green to C# scripting. Can you point me in the right direction for help regarding the method Josh suggested?

                        "You should instead just keep track of the highest profit the same time your strategy is trading. After it finishes a new trade, store cum profit to a variable. Check new cum profits versus previous cum profits. If it is higher then store the new value."

                        Comment


                          #13
                          vast524, this is just a generic programming concept - you save the current daily profit of the strategy to a double variable. Then as the strategy progresses throughout the day you check if the current Daily Profit is higher than your variable started at session start. If it is, just save the new (higher) value to the variable, if not you continue using the 'old' one as the high profit of the day.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          649 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          370 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          109 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          574 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          576 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X