Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intermittent Strategy Analyzer Failure

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

    Intermittent Strategy Analyzer Failure

    When testing strategies in Strategy Analyzer, I frequent run into an issue where clicking on the 'Run' button does not result in an actual run. I will see 'Calculating' and Iteration X / Y and the progress will appear, but it stops and returns to the idle state after a few seconds. The progress never starts painting green. Clicking again on 'Run' will usually succeed, but sometimes I must click more than once.

    It happens only when set to Optimization, not Backtest. I do not see any error messages in the main Log. Also, I use a lot of debug messages to Output1 and Output 2 and I see nothing appear in either log.

    I use Visual Studio a lot while debugging. I have tried setting the Exception settings to 'Break When Thrown' on all Exceptions in the CLR, when attached to NinjaTrader. The debugger never breaks, so it seems like this is not related to any exceptions deeper down in the CLR.

    I've been working with it this way for a while now, but it is getting frustrating. Do you have any suggestions on how to track down the cause?

    Thank you,


    #2
    Hello ChazJ,

    Are you able to reproduce this behavior with the Sample MA crossover included with NinjaTrader?

    After optimizing the script select the Chart display. Do you see data appearing on the chart?

    Add a print of the time to OnBarUpdate() outside of any conditions.
    Do the prints of the time appear in the output window?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      No I cannot reproduce this with SampleMACRossOver. I executed 'Run' at least 20 times with no failures. This confirms my suspicion that the issue is in my code. But with no apparent exceptions or other errors, I don't know what else I can do.

      Any other suggestions on how to track this down? Are there any other logs I can look at?

      Comment


        #4
        Hello ,

        The Log on the Control Center and the NinjaScript Output window are the two places information about a strategy will appear.

        I was not able to confirm, after optimizing the script select the Chart display. Do you see data appearing on the chart?

        Add a print of the time to OnBarUpdate() outside of any conditions.
        Do the prints of the time appear in the output window?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Interesting. When it fails, I do get messages to the output window. I am simply printing a short message plus CurrentBar.ToString(). But there are no results of any kind and also, there is no chart drawn. The print output is the same whether it works or not.

          I notice that there are separate threads running different parameters, each printing to the window. The last one ends at CurrentBar = 25333. Others end at different values.

          So what can we derive from this? Does it point to anything?

          Comment


            #6
            Hello ChazJ,

            Do you have multiple prints in the script?
            Please comment out the other prints and focus only on the time print at the top of OnBarUpdate().

            Do you have multiple scripts running that are printing?
            Please close all open workspaces and open a new chart and add only this one script.

            Are you seeing data on the chart?
            Do you see the prints of the time appearing in the output window?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              I think I may have found the cause of my issue.

              I was trying to do some more troubleshooting on this issue over the weekend by adding to the Print statement a variable that I use to track multiple instances in my code. As I was looking at how I use that variable, Visual Studio was telling me that it was defined in StrategyBase. I then noticed that StrategyBase uses the same name I used for my variable ('Id'). But somehow along the way, I lost the declaration for that variable (it was a private variable) that had previously pre-empted StrategyBase.Id due to the narrower scope. In my code, I was setting 'Id' to a random long number. The result was that I was setting the StrategyBase.Id variable to this random long number instead of what I thought was my private variable.

              After fixing this, I have run SA over a 20 times with no failures, whereas before, I was getting a failure rate of over 50%. I feel confident this was the cause, but you might ask your developers what this variable is used for and if could possibly have caused the problem (maybe it is never used in your code and could not in any way been the cause???).

              I was not aware until now that StrategyBase had a variable of the same name as the one I was trying to use. It would be interesting to know what this variable is used for. I tried to search for it in the docs but came up empty. Maybe you can research it and let me know for future reference.

              I would suggest that this variable (StrategyBase.Id) be made read-only in your code to avoid such issues in the future. It always seems to be set to a value of -1.


              Thanks,

              Comment


                #8
                Hello ChazJ,

                There are many properties behind the scenes that are not documented.

                Our development has let us know the StrategyBase.Id is used internally to track an strategy unique id.
                The default value for this is -1 until NinjaTrader begins using this to track information.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  Thanks for confirming. Looks like changing that value would definitely impact the NT engine. Again, I would recommend to your developers to make that variable (and any other variables not purposely exposed) a read-only variable. I can't think of any reason or purpose for external code to need to change it.


                  Comment


                    #10
                    Hello ChazJ,

                    Unfortunately, this cannot be read-only as the value does get set within the scope of the strategy class.

                    Instead, you cannot set values to this in the script.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by maybeimnotrader, Today, 05:46 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post maybeimnotrader  
                    Started by quantismo, Today, 05:13 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post quantismo  
                    Started by AttiM, 02-14-2024, 05:20 PM
                    8 responses
                    166 views
                    0 likes
                    Last Post jeronymite  
                    Started by cre8able, Today, 04:22 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post cre8able  
                    Started by RichStudent, Today, 04:21 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post RichStudent  
                    Working...
                    X