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

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 michi08, 10-05-2018, 09:31 AM
                    5 responses
                    741 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by The_Sec, Today, 02:29 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post The_Sec
                    by The_Sec
                     
                    Started by tsantospinto, 04-12-2024, 07:04 PM
                    4 responses
                    62 views
                    0 likes
                    Last Post aligator  
                    Started by sightcareclickhere, Today, 01:55 PM
                    0 responses
                    1 view
                    0 likes
                    Last Post sightcareclickhere  
                    Started by Mindset, 05-06-2023, 09:03 PM
                    9 responses
                    259 views
                    0 likes
                    Last Post ender_wiggum  
                    Working...
                    X