Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by rayyyu12, Today, 05:38 PM
    0 responses
    12 views
    0 likes
    Last Post rayyyu12  
    Started by xepher101, Yesterday, 12:19 PM
    2 responses
    29 views
    0 likes
    Last Post xepher101  
    Started by thumper57, Today, 04:30 PM
    0 responses
    8 views
    0 likes
    Last Post thumper57  
    Started by OllieFeraher, 05-09-2024, 11:14 AM
    5 responses
    16 views
    0 likes
    Last Post MisterTee  
    Started by jackiegils, Yesterday, 11:05 PM
    1 response
    11 views
    0 likes
    Last Post marcus2300  
    Working...
    X