Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetState Error

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

    SetState Error

    Hello everyone, I don't understand what's the matter
    I get the error SetState

    the code

    Code:
    
    private Series<double> Range2;
    
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "VariabiliteAlphaTest";
    Calculate = Calculate.OnBarClose;
    IsOverlay = true;
    DisplayInDataBox = true;
    DrawOnPricePanel = true;
    DrawHorizontalGridLines = true;
    DrawVerticalGridLines = true;
    PaintPriceMarkers = true;
    ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
    //See Help Guide for additional information.
    IsSuspendedWhileInactive = true;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute 1);
    
    Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }
    }
    
    
    protected override void OnBarUpdate()
    {
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    return;
    
    if (BarsInProgress == 1)
    {
    if (CurrentBar > 1)
    {
    
    if (Volume[0] >500) Range2[0] = Volume[0];
    
    if (Range2[0] > MAX(Range2, 5)[1] * 2) //Check to see if Current Bar greater then 3 bars starting on the previous[1] bars)
    {
    
    Draw.Diamond(this, "Diamond" + CurrentBar, true, -1, (High[0] + Low[0]) / 2, Brushes.Blue);
    Draw.Line(this, "Line4", false, -1, (High[0] + Low[0]) / 2, -100, (High[0] + Low[0]) / 2, Brushes.Blue, DashStyleHelper.Solid, 2);
    }
    }
    }
    
    }
    
    }
    }
    problems for some reason here

    if (Range2 [0]> MAX (Range2, 5) [1] * 2) // Check to see if Current Bar greater then 3 bars starting on the previous [1] bars)
    Last edited by memonolog; 04-21-2021, 08:58 AM.

    #2
    Hello memonolog,

    Thanks for your post.

    The custom series Range2 needs to be moved into State.DataLoaded.
    For Example:

    else if (State == State.Configure)
    {
    AddDataSeries(BarsPeriodType.Minute 1);
    }
    else if (State == State.DataLoaded)
    {
    Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
    }



    From the help guide:

    State.DataLoaded - DataLoaded is called only once after all data series have been loaded.

    •Use for logic that needs to access data related objects like Bars, Instruments, BarsPeriod, TradingHours or instantiating indicators

    •Notify that all data series have been loaded

    •Initialize any class level variables (including custom Series<T> objects)


    Reference: https://ninjatrader.com/support/help...tatechange.htm




    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello memonolog,

      Thanks for your post.

      The custom series Range2 needs to be moved into State.DataLoaded.
      For Example:

      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Minute 1);
      }
      else if (State == State.DataLoaded)
      {
      Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
      }



      From the help guide:

      State.DataLoaded - DataLoaded is called only once after all data series have been loaded.

      •Use for logic that needs to access data related objects like Bars, Instruments, BarsPeriod, TradingHours or instantiating indicators

      •Notify that all data series have been loaded

      •Initialize any class level variables (including custom Series<T> objects)


      Reference: https://ninjatrader.com/support/help...tatechange.htm



      thanks for the answer, moved the same error anyway!
      any other options?

      Comment


        #4
        Hello memonolog,

        Thanks for your reply.

        Please post the specific error message.

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello memonolog,

          Thanks for your reply.

          Please post the specific error message.
          picture

          Click image for larger version

Name:	error.png
Views:	234
Size:	7.7 KB
ID:	1152619

          Comment


            #6
            Code:
            else if (State == State.Configure)
            {
            AddDataSeries(BarsPeriodType.Minute, 1);
            
            Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
            }
            else if (State == State.DataLoaded)
            {
            Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);
            }
            }
            
            
            protected override void OnBarUpdate()
            {
            if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
            return;
            
            if (BarsInProgress == 1)
            {
            if (CurrentBar > 1)
            {
            
            if (Volume[0] > 500) { Range2[0] = Close[0]; }
            
            if (Range2[0] > MAX(Range2, 5)[1] * 2) //Check to see if Current Bar greater then 3 bars starting on the previous[1] bars)
            {
            
            Draw.Diamond(this, "Diamond" + CurrentBar, true, -1, (High[0] + Low[0]) / 2, Brushes.Blue);
            Draw.Line(this, "Line4", false, -1, (High[0] + Low[0]) / 2, -100, (High[0] + Low[0]) / 2, Brushes.Blue, DashStyleHelper.Solid, 2);
            }
            }
            }
            
            }
            21.04.2021 19:11:25;NinjaScript;Indicator 'VariabiliteAlphaTest': Error on calling 'SetState' method: Exception has been thrown by the target of an invocation.;

            Comment


              #7
              Hello memonolog,

              Thanks for your reply.

              Please remove the line "Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);" from State.configure and leave it in State.DataLoaded.


              Comment


                #8
                Originally posted by NinjaTrader_PaulH View Post
                Hello memonolog,

                Thanks for your reply.

                Please remove the line "Range2 = new Series<double>(this, MaximumBarsLookBack.Infinite);" from State.configure and leave it in State.DataLoaded.

                Result it's the same = error
                Last edited by memonolog; 04-21-2021, 01:37 PM.

                Comment


                  #9
                  Hello memonolog,

                  Thanks for your reply.

                  You have 3 public outputs for plots in Region Properties. Either comment them out now if you intend to use them later or remove them if not needed. Recompile, remove the previous version from the chart and apply the newly compiled version.


                  Comment


                    #10
                    Originally posted by NinjaTrader_PaulH View Post
                    Hello memonolog,

                    Thanks for your reply.

                    You have 3 public outputs for plots in Region Properties. Either comment them out now if you intend to use them later or remove them if not needed. Recompile, remove the previous version from the chart and apply the newly compiled version.

                    Thank you Paul.
                    solved.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    607 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    353 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    560 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    561 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X