Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple (?) coding question

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

    Simple (?) coding question

    I have the following code:

    #region Variables
    // Wizard generated variables
    private int sMAPeriod = 5; // Default setting for SMAPeriod
    // User defined variables (add any user defined variables below)
    private DataSeries myDataSeries;
    private DataSeries[,] mDS;
    #endregion

    /// <summary>
    /// This method is used to configure the indicator and is called once before any bar data is loaded.
    /// </summary>
    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
    CalculateOnBarClose = true;
    Overlay = false;
    PriceTypeSupported = false;

    // First initialize the straight DataSeries objects
    myDataSeries = new DataSeries(this);

    // Now initialize the 2D array
    int rows=2;
    int cols=2;
    int i,j;

    DataSeries[,] mDS = new DataSeries[rows, cols];
    for(i=0;i<rows;i++){
    for(j=0;j<cols;j++){
    mDS[i,j] = new DataSeries(this);
    }
    }
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    //mDS[0,0].Set(Open[0]);

    myDataSeries.Set(Close[0]);
    Plot0.Set(myDataSeries[0]);
    }

    This all works OK. But when I uncomment the line

    //mDS[0,0].Set(Open[0]);

    it produces no plot line - but it still compiles with no comment.

    Any ideas?

    Thanks.

    #2
    Please check your Control Center logs for runtime errors.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks.

      I guess it must be a c# error - it says "Object reference not set to instance of an object". So mDS[0,0] is not an instance? So is:

      mDS[0,0]=new DataSeries(this);

      wrong?

      I'm new to C#, old to C, Ruby...

      I guess I need to read some C# tutorials.

      N

      Comment


        #4
        Please try mDS[0][0] = new DataSeries(this);
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          That won't compile because I have the declaration:

          DataSeries[,] mDS;

          so I have to use 2 indices inside the [], so one of these must be wrong:

          DataSeries[,] mDS = new DataSeries[2, 2];

          mDS[0,0]= new DataSeries(this);

          I tried:

          DataSeries[,] mDS = new DataSeries[2, 2](this);

          and:

          DataSeries[,] mDS = new DataSeries(this)[2, 2];

          but neither will compile.

          The error says "object reference not set to an instance of an object" - and it's referring to the line:

          mDS[0,0].Set(Open[0]);

          So, mDS[0,0] must be the object reference (I guess this means pointer in the old C) that isn't set - but I thought : mDS[0,0]= new DataSeries(this);

          would set it.

          Comment


            #6
            b1g3ar5,

            Unfortunately making an array like this is beyond what we support. I have no other suggestions I can make at this time.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              So it's not a coding mistake it's just that it's not supported? That seems strange.

              I've just solved it - it was a coding mistake.

              Thanks.

              Comment


                #8
                It is likely a coding mistake. What I meant by not supported means it is beyond the scope of coding support we can offer as this is C# more so than NinjaScript.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Yes you are right - thanks anyway, Josh.

                  I'll read some C# tutorials.

                  N

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by sjsj2732, 03-23-2026, 04:31 AM
                  0 responses
                  69 views
                  0 likes
                  Last Post sjsj2732  
                  Started by NullPointStrategies, 03-13-2026, 05:17 AM
                  0 responses
                  312 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  306 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  146 views
                  1 like
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  105 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Working...
                  X