Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Convert array to series object

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

    Convert array to series object

    Hi all,

    Does anyone know the required syntax to convert an array to a series object?

    Thanks and regards
    MrSomebody

    #2
    Hi MrSomebody, thanks for your note.

    There are no existing methods to cast an array to a series. A series object is closely tied to the OnBarUpdate method and will have 1 index for every One would need to manually copy the memory from the array to a series object using a FOR loop, given this does not cause a performance issue.

    It is always recommended to use the Series object first as its conveniently managed by NinjaTrader. I made a sort of contrived example:

    Code:
    public class TestCopyArray : Indicator
        {
            private List<double> BigList;
            private Series<double> BigSeries;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "TestCopyArray";
                    Calculate                                    = Calculate.OnBarClose;
                    IsOverlay                                    = false;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event. 
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                    BigList = new List<double>();
                    BigSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);
    
                    var count = 0;
                    do
                    {
                        BigList.Add(Math.Sqrt(Math.Sin(DateTime.Now.Millisecond)));
                        count++;
                    }
                    while(count < 100);
    
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(CurrentBar < BigList.Count) return;
                foreach(var val in BigList)
                {
                    BigSeries[0] = val;
                }
    
                for(int i = CurrentBar; i > 0; i--)
                {
                    Print(BigSeries[i]);
                }
    
                Print("");
                Print(BigSeries.Count);
    
            }
        }
    Attached Files

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    646 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    367 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    107 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    569 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X