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

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




    Paul H.NinjaTrader Customer Service

    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.

        Paul H.NinjaTrader Customer Service

        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:	184
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.


              Paul H.NinjaTrader Customer Service

              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.


                  Paul H.NinjaTrader Customer Service

                  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 cre8able, Yesterday, 07:24 PM
                    1 response
                    13 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by cocoescala, 10-12-2018, 11:02 PM
                    6 responses
                    939 views
                    0 likes
                    Last Post Jquiroz1975  
                    Started by gbourque, Today, 06:39 AM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by cmtjoancolmenero, Yesterday, 03:58 PM
                    1 response
                    17 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by benmarkal, Yesterday, 12:52 PM
                    3 responses
                    23 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X