Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

A different OnStartUp question

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

    A different OnStartUp question

    Hi,

    This is a question about OnStartUp but 100% separate from my earlier question of yesterday.

    If the answer you would give is - this is undocumented, then if possible please point me in the right direction.

    Is the NinjaTrader internal call to OnStartUp synchronous in that I can do as much processing in OnStartUp as needed without being concerned about timing issues? This is primarily related to optimization but if there is a general answer to this, that would be best.

    I am writing some custom code for optimization and I need to instantiate a dll that may or may not have been fully initialized internally (I know NT loads it).

    The initialization can take a while as it needs to verify the state of an external database, initialize certain things within the database and in general do a lot of stuff.

    The easiest and cleanest place for me to do that is in the constructor of the primary dll class but I also don't want to cause other issues within NT.

    Central to my issue with OnStartUp is that in a sense, for an optimization run, it is recursive-like, in that I don't have any NT methods/variables to let me know where I am in the process.

    I might be at the very beginning of the first backtest run or I might be 100 iterations into the process. I keep various state variables in the dll (and from there at times in the database) so that isn't the issue; I just don't want to affect the timing of how the optimizer works.

    Best Regards,
    Scott
    Last edited by ScottB; 04-08-2011, 09:01 AM.

    #2
    Hi Scott,

    Before we introduced this event, we recommended people perform OnStartUp-like operations on the first bar. OnStartUp() essentially mimics this:

    if(CurrentBar == 0)

    It's called for each distinct optimization run, so you would have to custom code any controls if you intend certain code to be run only once rather than each test.

    It may help to Print() your computer clock time to track the flow of processing between OnStartup() and OnBarUpdate() for each iteration of the optimization tests.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      Thanks for getting back to me; I need a little clarification. This code will never run under any circumstances except during an optimization; there is a strategy parameter that dictates what mode we are in.

      My understanding/analysis is:

      With OnBarUpdate, the method is being driven by external events i.e. a tick arrives and is therefore under normal circumstances, time sensitive. I have used the VS debugger and I can say something in the call chain gets decidedly unhappy if I sit on a breakpoint too long if the chain originates in OnBarUpdate (NT will crash).

      OnStartUp, while likely being raised as an event, is (or can be) completely synchronous with no timing issues because at that point, nothing needs to happen, especially if we are optimizing. The method isn't logically being driven by external events (I recognize it may be code wise though) .

      So, if I started a process that took 5 minutes in OnBarUpdate (to use a value that would never happen) that would be a deal breaker because of incoming ticks but wouldn't matter to me as a user if it were in OnStartUp.

      Because although the strategy would appear to be slow to load, in the end, it wouldn't really matter if it were only done once and wouldn't matter at all if I am optimizing.

      However, this all assumes there are no sync issues nor any sort of a time out for processing done in OnStartUp and that is the crux of my question.

      Best Regards,
      Scott

      Comment


        #4
        Unfortunately this is beyond our scope of support and can't comment on OnStartup() internals. There is very little we can offer with regards to expectations running NinjaScript code in Visual Studio environment.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan, I didn't expect any comment on the VS part of the question; I completely understand the support issue.

          I can distill this down to a relatively simple question. If I am optimizing a strategy, are there any timing dependencies between OnStartUp and anything else.

          If I have a relatively long running process in OnStartUp, will that affect any other part of the NT initialization process?

          Best Regards,
          Scott

          Comment


            #6
            We're not aware of any issues you may run into with OnStartup() timing. If you see something, please let us know and we will look into.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Ryan, thanks. I doubt I will see anything but just to be safe I am going to go into debug mode with VS and stop the execution in OnStartUp for a bit and see if it causes any issues.

              If it does I will let you know but I don't see that as an issue with NT but rather one with what I am doing.

              Best Regards,
              Scott

              Comment


                #8
                Originally posted by ScottB View Post
                Ryan, I didn't expect any comment on the VS part of the question; I completely understand the support issue.

                I can distill this down to a relatively simple question. If I am optimizing a strategy, are there any timing dependencies between OnStartUp and anything else.

                If I have a relatively long running process in OnStartUp, will that affect any other part of the NT initialization process?

                Best Regards,
                Scott
                It looks like your only real option will be to run a state loop in OnStartUp(), so that it can escape the function only after you are properly set up.

                Comment


                  #9
                  koganam, it won't affect my code, I was more concerned with crashing NT because it was expecting a relatively quick return.

                  Comment


                    #10
                    I just want to report back there does not appear to be any timing dependencies.

                    You can also determine programmatically whether you are in a back test, optimization or live but I have yet to be able to directly determine what iteration I am on in a optimization.

                    One challenge to doing that is the multithreading of the back test engine. If anyone knows how to get the iteration number (not the total, I can already do that programmatically), please post it or feel free to pm me.

                    Best Regards,
                    Scott

                    Comment


                      #11
                      Hi Scott,

                      Maybe consider writing to a file during OnStartUp(). This thread may be helpful for avoiding file locks:
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        Ryan, I am actually using SQL Server as a back end which completely eliminates any concurrency problems. I can handle the iterations via an Identity column in the database but was hoping for a way to get it programmatically.

                        I must say, I love the performance of the back test engine.

                        Best Regards,
                        Scott

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        671 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        379 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        111 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        575 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        582 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X