Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

method: 'AddDataSeries' cannot be called from this state.

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

    method: 'AddDataSeries' cannot be called from this state.

    Jesse,

    After much frustration, this indicator is working quite well for me now, enough so I have stopped filling in spreadsheets daily. :-) Much thanks!

    Now time to convert to NT8. How do I convert this line? I do not see it on the page that illustrates the specific syntax changes from NT7 to NT8. Add(PeriodType.Minute, 1440);

    My lines in action in NT7. http://screencast.com/t/2ql2JD8by

    Best regards,

    Dolfan

    #2
    Hello,

    I am glad to hear the indciator is working as you would like it to.

    For NT8 items, please ensure to post future questions in the NT8 forums.

    For finding specific items that are different, the Code breaking changes page is helpful for that specifically. http://ninjatrader.com/support/helpG...ng_changes.htm

    The first few items are actually what you are looking for, in regard to a Indicator adding Data, you would be looking for AddDataSeries() http://www.ninjatrader.com/support/h...dataseries.htm

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I believe I added the syntax precisely but I ended up with the following errors in the Output window.

      Error on calling 'OnStateChange' method: 'AddDataSeries' cannot be called from this state. Please see the Help Guide article on 'AddDataSeries' for more information.

      Here is the syntax...

      protected override void OnStateChange()
      {
      AddDataSeries(BarsPeriodType.Minute, 1440); // Sets the bars for calculations to 1440 minute Bars

      Comment


        #4
        Hello,

        I have moved these replies into a new NT8 thread as this is no longer related to the original NT7 questions you had asked.

        Regarding the error, you would need to review the help guide sample as it is different than what you have provided. http://ninjatrader.com/support/helpG...dataseries.htm

        In the sample you will see the following syntax which was not included in what you had provided:

        Code:
        if (State == State.Configure)
        {
        
        }

        OnStateChange is called for multiple states, by not checking what state the code you are executing is in, you are executing it in all states which would be incorrect at some points causing an error.

        If you instead use the syntax exactly as the sample shows you should no longer receive this error.

        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thanks Jesse, and thanks for moving the thread. I wouldn't know how to simply 'move' a conversation in here.

          The chart is finally able to load the indicator now but I get no lines as coded. I am confused about some of the regions and whether or not some of them remain, are coded elsewhere, renamed, etc, I now have the following error;

          Value of property 'Period' of NinjaScript 'AAASRLines' is 0 and not in valid range between 1 and 2147483647.

          In the Variables region I have the following;

          #region Variables

          private int sessionCount = 0;
          private double high = 0;
          private double low = 0;
          private double open = 0;
          private double range = 0;
          private int period = 0;
          // User defined variables (add any user defined variables below)
          #endregion

          However, I get the feeling this step, region or region name is no longer necessary, encompassed elsewhere or renamed. Please help me clear the fog. :-)

          Best regards,

          Dolfan

          Comment


            #6
            Hello,

            The Property Period mentioned in the error is not the same as the variable period you have shown:
            private int period = 0;
            lowercase period is a backing field whereas the error mentions the public property Period.

            This is important, this would mean the error is saying the public property's value is not between the range needed, you can verify this by seeing where you set the Public property and what its value is being set to.

            Could you provide the property definition instead of the private period = 0; definition? Likely you instead need to assign the value from State.SetDefaults as

            Period = 0;

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Here are the 1st two call outs for that region.

              [Range(1, int.MaxValue)]
              [NinjaScriptProperty]
              [Display(Name="Period", Description="Numbers of bars used for calculations", Order=1, GroupName="Parameters")]
              public int Period
              { get; set; }


              [Range(1, int.MaxValue)]
              [NinjaScriptProperty]
              [Display(Name="Period", Description="Numbers of bars used for calculations", Order=1, GroupName="Parameters")]
              public Series<double> UpperMagenta
              { get; set; }

              I really don't think they are correct but I am trying to follow the format provided in this link;



              After spending much time in NT7 getting this figured out, NT8 has me reeling again.

              Dolfan

              Comment


                #8
                Hello,

                These would be correct properties, but there is a C# concept that is being missed here.

                The Public property uses a get; set; This would entail there is no Backing Field and there is only a Public Property.

                You are assiging a value to a Backing Field that is not associated with anything rather than assigning a value to the property.

                Here is a example of a public property that uses a backing field:
                Code:
                [B]private int period = 0;[/B]
                
                [Range(1, int.MaxValue)]
                [NinjaScriptProperty]
                [Display(Name="Period", Description="Numbers of bars used for calculations", Order=1, GroupName="Parameters")]
                public int Period
                { 
                    [B]get { return period; } 
                    set { period = value;}[/B] 
                }
                Here is an example of a public property that does not use a backing field:

                Code:
                [Range(1, int.MaxValue)]
                [NinjaScriptProperty]
                [Display(Name="Period", Description="Numbers of bars used for calculations", Order=1, GroupName="Parameters")]
                public int Period
                { get; set; }
                The get and set delegate if the backing field is being used or not, you are not using the backing field so the Public Property only would need to be used in the script. you can delete the:

                Code:
                private int period = 0;
                and instead only use Period throughout the script along with setting Period to a value from SetDefaults:

                Code:
                Period = 0;

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by geddyisodin, Today, 05:20 AM
                0 responses
                3 views
                0 likes
                Last Post geddyisodin  
                Started by JonesJoker, 04-22-2024, 12:23 PM
                6 responses
                32 views
                0 likes
                Last Post JonesJoker  
                Started by GussJ, 03-04-2020, 03:11 PM
                12 responses
                3,239 views
                0 likes
                Last Post Leafcutter  
                Started by AveryFlynn, Today, 04:57 AM
                0 responses
                5 views
                0 likes
                Last Post AveryFlynn  
                Started by RubenCazorla, 08-30-2022, 06:36 AM
                3 responses
                79 views
                0 likes
                Last Post PaulMohn  
                Working...
                X