Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

This Indicator is crashing NT.

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

    This Indicator is crashing NT.

    Attached is just a sample Indicator that is part of a larger project. When I try to load the NT Indicator list, this indicator crashes NT. I have attached the zip and removed everything from it except for the code that is pertinent. Can you take a peek at it and give me a nudge in the right direction? I can't figure this one out.
    Attached Files

    #2
    to prevent crash

    move
    Code:
    sectors.Add(new S("XLK",26.28));
    from
    Code:
    if (State == State.SetDefaults)
    to
    Code:
    else if (State == State.DataLoaded)

    to prevent further endless cpu usage

    update

    Code:
            public class S
            {
    
                private double weight;
    
                public S(string ticker,double weight)
                {
                    Ticker = ticker;
                    Weight = noWeighting ? 100 : weight;
                }
    
                public double Weight
                {
                    get { return noWeighting ? 100 : weight; }
                    set { weight = value; }
                }
    
                public string Ticker
                {
                    get;
                    set;
                }
    
            }

    additional note

    if you ever load this indicator onto a chart that is not minute-based, you may get irregular results, depending on what your full code is actually doing. This is due to
    Code:
    AddDataSeries("XLK",BarsPeriodType.Minute,BarsPeriod.Value);
    For example, if you run this indicator on a daily chart, BarsPeriod.Value is 1, your added dataseries would therefore be based on 1 minute bars.
    If you are trying to keep your added dataseries' timeframe the same as your primary bars, you can try using
    Code:
    AddDataSeries("XLK");
    Last edited by gubbar924; 10-09-2018, 03:41 AM.

    Comment


      #3
      Hello swooke,

      Thanks for your post. And thank you gubbar924 for providing suggestions to help swooke fix his code.

      I have included a video and some that explains the NinjaScript lifecycle and how OnStateChange can be used with best practices. Essentially, operations that do not depend on data being loaded should be done in State.Configure, operations that do depend on data should be done in State.DataLoaded. BarsPeriod.Value would depend on data being loaded and may not always be available in State.Configure which is why using AddDataSeries("XLK"); would be recommended.

      Suggested reading for the NinjaScript LifeCycle and Best practices is linked below.Please let us know if you have any questions on the material.
      Attached Files

      Comment


        #4
        Jim,

        Is there any way you could comment on my really stripped down script? I reduced it from about 2500 lines to demonstrate a the issue. I tried following the advice given in the previous post but NT still crashed. The script is pretty small. I just need a little direction on where I am going wrong.

        Comment


          #5
          Hello swooke,

          The code that is generating the issue is from your custom class and HashSet code. This sort of implementation would be outside the context of NinjaScript support. The issue sounds like you are caught in an infinite loop. Looking at the code provided, I would suggest checking your getters and setters for any recursive operations to troubleshoot further. For example, referencing the same public property in the getter instead of getting the backing field property or setting the backing field with the public property instead of value in the setter.

          Here is an example that can be modeled:

          Code:
          public string DisplayText
          {
              get { return displayText; }
              set
              {
                  if (displayText == value)
                      return;
                  displayText                = value;
                  needsLayoutUpdate     = true;
              }
          }

          Comment


            #6
            Thanks for the direction. That was a big help. One last question, is it a common design pattern to stop the render function when a user opens the settings window? Is this just done with an if statement at the top of the render function to check of the window is open?

            Comment


              #7
              Hello swooke,

              This is not a common practice. Charts will still update with the indicator dialog open, for example, and skipping rendering operations would prevent the indicator from updating visually with this open. I'm also not aware of any supported way to do this.

              Best Practices for performance when writing NinjaScript can be referenced here - https://ninjatrader.com/support/help...tm#Performance

              Please let us know if you have any questions.

              Comment

              Latest Posts

              Collapse

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