Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NinjaTrader.Data.Period is a type but is used like a variable

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

    NinjaTrader.Data.Period is a type but is used like a variable

    I'm new to coding and am trying to compile a simple indicator strategy. The error message "NinjaTrader.Data.Period is a type but is used like a variable" pops up when I try and compile.

    Here is some of the code:

    ///<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, "Upper"));
    Add(
    new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "Middle"));
    Add(
    new Plot(Color.FromKnownColor(KnownColor.DarkViolet), PlotStyle.Line, "Lower"));
    CalculateOnBarClose =
    true;
    Overlay =
    true;
    PriceTypeSupported =
    true;
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    Upper.Set(SMA(Period)(0) + ATR(Period)[0]);
    Middle.Set(SMA(Period)(
    0));
    Lower.Set(SMA(Period)(
    0) - ATR(Period)[0]);

    -----------------------------------------------------------

    The compile error refers to lines 48,49 and 50:

    Upper.Set(SMA(Period)(0) + ATR(Period)[0]);
    Middle.Set(SMA(Period)(
    0));
    Lower.Set(SMA(Period)(
    0) - ATR(Period)[0]);

    After attempting a number of solutions, I can't wrap my head around what the problem is. Any help will be appreciated. Thanks.

    John

    #2
    Try replacing (0) with [0]

    VT

    Comment


      #3
      Unfortunately I get the same error message using "[]" as opposed to
      "()".

      Comment


        #4
        Did you actually make a variable called Period? Please see the SMA indicator and see how they did so in the Variables and Properties region of the code.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks, Josh. I was able to upload the indicator but it crashed NT when I tried to use it. I'll continue to work on it and see if I can figure out what caused this.





          *In fareness to the creator of this indicator, this is not my original work. I'm simply trying to code the indicator by hand to learn the language.

          Comment


            #6
            "Your indicator likely holds one or more recursive properties which could case NinjaTrader to crash: period"

            Does anyone know what this message refers to?

            Comment


              #7
              Jwash,

              Suspect you created your parameter as "period" instead of "Period". Please copy paste what you have in the Properties region of your code in relation to this variable. Thank you.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                #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 Upper
                {
                get { return Values[0]; }
                }
                [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 Middle
                {
                get { return Values[1]; }
                }
                [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 Lower
                {
                get { return Values[2]; }
                }
                [Description(
                "")]
                [Category(
                "Parameters")]
                publicint period
                {
                get { return period; }
                set { period = Math.Max(1, value); }
                }
                #endregion
                }

                Comment


                  #9
                  This part is wrong.
                  Code:
                  [FONT=Courier New][SIZE=2][Description([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])]
                  [Category([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Parameters"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] period
                  {
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] { [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] period; }
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] { period = Math.Max([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], value); }
                  }[/SIZE][/FONT]

                  Should be
                  Code:
                  [FONT=Courier New][SIZE=2][Description([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])]
                  [Category([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"Parameters"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff] int[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] [SIZE=5][B]P[/B][/SIZE]eriod
                  {
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]get[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] { [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] period; }
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]set[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] { period = Math.Max([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], value); }
                  }[/SIZE][/FONT]
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Got it. Thanks a lot.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    581 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    338 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
                    554 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    552 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X