Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with DataSeries object

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

    Problem with DataSeries object

    This problems happens when you add a custom dataseries in the code, not when you use the indicator provided dataseries.

    In the following code, there are 2 Dataseries : Barnum, which is automatically added by the Add(new Plot...) method, and the dsOpen dataseries which is added manually by code.

    Both dataseries are set as value(bar)=bar number, so when plotting they should show a straight line.

    This is OK for the Barnum bar series (red), but the manual bar series repeats the last values.

    Code:
            protected DataSeries dsOpen;
           
            protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Barnum"));
                CalculateOnBarClose    = true;
                Overlay                = false;
                
                if (Instrument != null)
                {
                    dsOpen     = new DataSeries(this);
                }
            }
    
          protected override void OnBarUpdate()
            {
                dsOpen.Set(CurrentBar);
                Barnum.Set(CurrentBar);
            }
     
            public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
            {
                int lastBar        = Math.Min(ChartControl.LastBarPainted, Bars.Count - 1);
                int barsPainted = ChartControl.BarsPainted;
                int firstBar    = Math.Max(0, (lastBar - barsPainted) + 1);
                
                int x;
                for (int idx = firstBar; idx <= lastBar; idx++)
                {
                    x=ChartControl.GetXByBarIdx(Bars,idx);
                    graphics.DrawArc(new Pen(Color.Black,1),x,ChartControl.GetYByValue(this,dsOpen.Get(idx)),1,1,0,360);            
                    graphics.DrawArc(new Pen(Color.Red,1),x,ChartControl.GetYByValue(this,Barnum.Get(idx)),1,1,0,360);            
                    
                }
            }
    Attached Files

    #2
    Data Series objects by default only store 256 values now. I suggest you do actual prints of the values to see what is happening under the hood. Unfortunately Plot override is not supported.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      The question was not about he plot, it was merely there to show you the problem in a graphical way.

      Yes it looks like that the dataseries cycle on the last 256 values. Is this limitation going to disappear ?

      Comment


        #4
        This is the new memory saving default behavior of custom data series. In case you wanted to have back the old "infinite lookback" logic please use this:
        Code:
        new DataSeries(this, MaximumBarsLookBack.Infinite)

        Comment


          #5
          OK thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          596 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          554 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X