• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Array syntax error

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

    Array syntax error

    I am trying to use a simple 10 element array. However when I compile the first reference in the on bar update section gives me CS0103 error "The name 'aUpline' does not exist in the current context" I assume it is a simple syntax error but I can't figure out what it might be.
    under variables I declare and initialize:

    double[] aUpline = {0,1.7,1.3,1,0.7,0.3,0,-0.3,-0.7,-1};


    under OnBarUpdate() this is the line giving me the error

    Line9ua.Set(bMainLine + aUpLine[9] + TickSize * ZoneWidth);

    Not sure if I have to declare, initialize and assign differently. Any help would be appreciated.

    Thanks,
    Ryan

    #2
    Originally posted by RyanR View Post
    I am trying to use a simple 10 element array. However when I compile the first reference in the on bar update section gives me CS0103 error "The name 'aUpline' does not exist in the current context" I assume it is a simple syntax error but I can't figure out what it might be.
    under variables I declare and initialize:

    double[] aUpline = {0,1.7,1.3,1,0.7,0.3,0,-0.3,-0.7,-1};


    under OnBarUpdate() this is the line giving me the error

    Line9ua.Set(bMainLine + aUpLine[9] + TickSize * ZoneWidth);

    Not sure if I have to declare, initialize and assign differently. Any help would be appreciated.

    Thanks,
    Ryan
    c# is case sensitive. You declared "aUpline". but are trying to reference "aUpLine[9]". They are not the same object.

    Comment


      #3
      Ryan, with Koganam's helpful hint in mind, can you please try this changed line to access -

      Line9ua.Set(bMainLine + aUpline[9] + TickSize * ZoneWidth);
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thanks koganam and Bertrand, but even after the correction I have the same error

        The new line in variables:

        double[] aUpLine = {0,1.7,1.3,1,0.7,0.3,0,-0.3,-0.7,-1};

        the error line in main code section

        Line9ua.Set(bMainLine + aUpLine(9) + TickSize * ZoneWidth);

        So if I am clear the fact that I initialized when declared under variables I don't need to do anything in the initialize section?

        Thanks
        Ryan

        Comment


          #5
          Ryan, please try with this call instead in the variables region (so with class scope), works well in my testing -

          private double[] aUpLine = new double [] {0.0, 1.0, 7.0, 1.3, 1.0, 0.7, 0.3, 0.0, -0.3, -0.7, -1.0};
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Still no luck. The code is below. I have tried to separately declare and initialize, combine the two as shown etc. and can not get this to compile. I would really appreciate any help anyone can provide. Thanks!

            PHP Code:
            namespace NinjaTrader.Indicator
             
            {
             
            ///<summary>
            /// Enter the description of your new custom indicator here
            ///</summary>
            [Description("Dynamic horizontal lines")]
             
            publicclass DynamicLinestest Indicator
             
            {
             
            #region Variables
             // Wizard generated variables
            int[] sbn;
             
            privatedouble[] upLine newdouble [] {0.01.751.251.00.750.250.0, -0.25, -0.75, -1.0}; 
             
            privatedouble bMainLine 104.00// Default setting for MainLine

             
            privateint groupNumber=2;
             
            privateint zoneWidth 1// Default setting for ZoneWidth
            privateint opacity 3;
             
            privateint shadingBarsBack 130// BarsBack to shade the lemgth of lines
            privateint y=0;
             
             private 
            Color colorShading Color.Lime;
             
             private 
            DataSeries Line9ua;
             private 
            DataSeries Line9ub;
             private 
            DataSeries Line8ua;
             private 
            DataSeries Line8ub;
             private 
            DataSeries Line7ua;
             private 
            DataSeries Line7ub;
             private 
            DataSeries Line6ua;
             private 
            DataSeries Line6ub;
             private 
            DataSeries Line5ua;
             private 
            DataSeries Line5ub;
             private 
            DataSeries Line4ua;
             private 
            DataSeries Line4ub;
             private 
            DataSeries Line3ua;
             private 
            DataSeries Line3ub;
             private 
            DataSeries Line2ua;
             private 
            DataSeries Line2ub;
             private 
            DataSeries Line1ua;
             private 
            DataSeries Line1ub;
             
             
             
             
            // User defined variables (add any user defined variables below)
            #endregion
            ///<summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            ///</summary>
            protectedoverridevoid Initialize()
             {
             
            Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line"Plot0"));
             
            Overlay true;
             
             
            Line9ua = new DataSeries(this);
             
            Line9ub = new DataSeries(this);
             
            Line8ua = new DataSeries(this);
             
            Line8ub = new DataSeries(this);
             
            Line7ua = new DataSeries(this);
             
            Line7ub = new DataSeries(this);
             
            Line6ua = new DataSeries(this);
             
            Line6ub = new DataSeries(this);
             
            Line5ua = new DataSeries(this);
             
            Line5ub = new DataSeries(this);
             
            Line4ua = new DataSeries(this);
             
            Line4ub = new DataSeries(this);
             
            Line3ua = new DataSeries(this);
             
            Line3ub = new DataSeries(this);
             
            Line2ua = new DataSeries(this);
             
            Line2ub = new DataSeries(this);
             
            Line1ua = new DataSeries(this);
             
            Line1ub = new DataSeries(this);
             
             
            int[] sbn= {0,0,0,0};
             }
             
            ///<summary>
            /// Called on each bar update event (incoming tick)
            ///</summary>
            protectedoverridevoid OnBarUpdate()
             {
             Print(
            bMainLine+" CB="+CurrentBar+" SBB="+shadingBarsBack);
             
            // Use this method for calculating your indicator values. Assign a value to each

             
            if(CurrentBar shadingBarsBack 5)
             return;
             if (
            CurrentBar==(shadingBarsBack+5)) //Set initial Center line
            {
             
            bMainLine=Math.Truncate(Close[0]);
             goto 
            Draw;
             
             
            //Set initial values for 3 levels based on initial center line 
            sbn[1]=shadingBarsBack
             
            sbn[2]=shadingBarsBack
             
            sbn[3]=shadingBarsBack
            // } 

             
            Print(bMainLine);
             }
             
            //If Currnt bar > CurrentBar +5 check direction
            ////////////////////////////
            /// //No direction change
            /// //////////////////////////

             
            elseif ((Close[0]<(bMainLine+1.15))&&(Close[0]>(bMainLine-0.15)))
             {
             for (
            int x=1x<4x++) 
             {
             if (
            sbn[x]<shadingBarsBack)
             {
             
            sbn[x]=sbn[x]+1
             }
             } 
             goto 
            Draw
             }
             
            //////////////////////////////
            /// //Up direction change
            /// /////////////////////////

             
            elseif (Close[0]>(bMainLine+1.15))
             {
             
            groupNumber=groupNumber-1
             if (
            groupNumber==0
             {
             
            groupNumber=3;
             }
             
            y=groupNumber
             for (
            int x=1x<4x++) 
             {
             
            upLine[x+((y-1)*3)]=(upLine[x+((y-1)*3)]+3); 
             }
             
            sbn[y]=0
             goto 
            Draw
             }
             
             
            ////////////////////////////////////
            /// //Down direction change
            /// ////////////////////////////////
            elseif (Close[0]<(bMainLine-0.15))
             {
             
            groupNumber=groupNumber+1
             if (
            groupNumber==4
             {
             
            groupNumber=1;
             } 
             
            y=groupNumber;
             for (
            int x=1x<4x++) 
             {
             
            upLine[x+((y-1)*3)]=(upLine[x+((y-1)*3)]-3); 
             } 
             
            sbn[y]=0;
             goto 
            Draw
             
             }
             
            Draw:
             
            Line9ua.Set(bMainLine upLine(9) + TickSize ZoneWidth); 
             
            Line9ub.Set(bMainLine upLine(9) - TickSize ZoneWidth);
             
            Line8ua.Set(bMainLine upLine(8) + TickSize ZoneWidth);
             
            Line8ub.Set(bMainLine upLine(8) - TickSize ZoneWidth);
             
            Line7ua.Set(bMainLine upLine(7) + TickSize ZoneWidth);
             
            Line7ub.Set(bMainLine upLine(7) - TickSize ZoneWidth);
             
            Line6ua.Set(bMainLine upLine(6) + TickSize ZoneWidth);
             
            Line6ub.Set(bMainLine upLine(6) - TickSize ZoneWidth);
             
            Line5ua.Set(bMainLine upLine(5) + TickSize ZoneWidth);
             
            Line5ub.Set(bMainLine upLine(5) - TickSize ZoneWidth);
             
            Line4ua.Set(bMainLine upLine(4) + TickSize ZoneWidth);
             
            Line4ub.Set(bMainLine upLine(4) - TickSize ZoneWidth);
             
            Line3ua.Set(bMainLine upLine(3) + TickSize ZoneWidth);
             
            Line3ub.Set(bMainLine upLine(3) - TickSize ZoneWidth);
             
            Line2ua.Set(bMainLine upLine(2) + TickSize ZoneWidth);
             
            Line2ub.Set(bMainLine upLine(2) - TickSize ZoneWidth);
             
            Line1ua.Set(bMainLine upLine(1) + TickSize ZoneWidth);
             
            Line1ub.Set(bMainLine upLine(1) - TickSize ZoneWidth); 
             
             
             
             
            DrawRegion("tag40"sbn[3],0,Line9ua ,Line9ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag43"sbn[3],0,Line8ua ,Line8ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag44"sbn[3],0,Line7ua ,Line7ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag46"sbn[2],0,Line6ua ,Line6ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag48"sbn[2],0,Line5ua ,Line5ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag50"sbn[2],0,Line4ua ,Line4ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag52"sbn[1],0,Line3ua ,Line3ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag54"sbn[1],0,Line2ua ,Line2ub,Color.Empty,colorShading,Opacity);
             
            DrawRegion("tag56"sbn[1],0,Line1ua ,Line1ub,Color.Empty,colorShading,Opacity);
             
             
             
             Print(
            bMainLine+" CB="+CurrentBar+" SBB="+shadingBarsBack);
             
             
             }
             
            #region Properties
             
            [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries Plot0
             
            {
             
            get { return Values[0]; }
             }
             
             
            // [Description("")]
             // [GridCategory("Parameters")]
             // public double BMainLine
             // {
             // get { return bMainLine; }
             // set { bMainLine = value; }
             // }

             
             //************************************************

             // Color Shading

             
            [XmlIgnore()]
             [
            Description("Color for Shading")]
             [
            GridCategory("Parameters")]
             public 
            Color ColorShading
             
            {
             
            get { return colorShading; }
             
            set colorShading value; }
             }
             
             
            // Serialize our Color object
            [Browsable(false)]
             
            publicstring ColorShadingSerialize
             
            {
             
            get { return NinjaTrader.Gui.Design.SerializableColor.ToString(colorShading); }
             
            set colorShading NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
             }
             
             
             [
            Description("")]
             [
            GridCategory("Parameters")]
             
            publicint ZoneWidth
             
            {
             
            get { return zoneWidth; }
             
            set zoneWidth value; }
             }
             
             [
            Description("")]
             [
            GridCategory("Parameters")]
             
            publicint ShadingBarsBack
             
            {
             
            get { return shadingBarsBack; }
             
            set shadingBarsBack value; }
             }
             
             [
            Description("")]
             [
            GridCategory("Parameters")]
             
            publicint Opacity
             
            {
             
            get { return opacity; }
             
            set opacity value; }
             }
             
             
            #endregion
            }
             } 

            Comment


              #7
              Should compile normally Ryan, if you access your array values correctly through the [ ] brackets -

              i.e. Line9ua.Set(bMainLine + upLine[9] + TickSize * ZoneWidth);
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Ahh! Fantastic (I had fixed that earlier not sure why I pasted it back)

                Appreciate all the help.

                Ryan

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by richa61416, Today, 01:18 PM
                0 responses
                2 views
                0 likes
                Last Post richa61416  
                Started by Robotman, Today, 01:08 PM
                0 responses
                3 views
                0 likes
                Last Post Robotman  
                Started by StevenNelson, Today, 12:29 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by anupsoni, Today, 12:23 PM
                1 response
                3 views
                0 likes
                Last Post NinjaTrader_Kate  
                Started by aligator, Yesterday, 12:15 PM
                8 responses
                62 views
                0 likes
                Last Post NinjaTrader_Heath  
                Working...
                X