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

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
      JimNinjaTrader Customer Service

      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;
              }
          }
          JimNinjaTrader Customer Service

          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.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by wzgy0920, 04-20-2024, 06:09 PM
              2 responses
              26 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, 02-22-2024, 01:11 AM
              5 responses
              32 views
              0 likes
              Last Post wzgy0920  
              Started by wzgy0920, Yesterday, 09:53 PM
              2 responses
              49 views
              0 likes
              Last Post wzgy0920  
              Started by Kensonprib, 04-28-2021, 10:11 AM
              5 responses
              192 views
              0 likes
              Last Post Hasadafa  
              Started by GussJ, 03-04-2020, 03:11 PM
              11 responses
              3,234 views
              0 likes
              Last Post xiinteractive  
              Working...
              X