Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnStartup

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

    OnStartup

    Hi,

    Is there a way to force an indicator to call OnStartUp or to at least predict when it will be called? I have a dll I am trying to debug and while it appears Initialize() is reliably called, OnStartUp seems not to be or certainly not in a reliable way. I have certain things that can only be done in OnStartUp.

    I am using Visual Studio to debug and have done this enough with strategies to have a very good idea of what I am doing but may be missing something when applying it to an indicator.

    I have had an issue with this in the past and restarting NinjaTrader would normally solve it but not this time.

    Thanks in advance
    Scott

    #2
    Originally posted by ScottB View Post
    Hi,

    Is there a way to force an indicator to call OnStartUp or to at least predict when it will be called? I have a dll I am trying to debug and while it appears Initialize() is reliably called, OnStartUp seems not to be or certainly not in a reliable way. I have certain things that can only be done in OnStartUp.

    I am using Visual Studio to debug and have done this enough with strategies to have a very good idea of what I am doing but may be missing something when applying it to an indicator.

    I have had an issue with this in the past and restarting NinjaTrader would normally solve it but not this time.

    Thanks in advance
    Scott
    If OnStartUp() is acting up, move the code to a if (CurrentBar ==0) controlled block in OBU. I actually have a certain construct that does not work in OnStartUp(), period! That is how I discovered that I had to go to the old standby from eons past.

    Comment


      #3
      koganam, Thanks for the input. I was hoping it was something basic I had done and the platform was beyond the need to use the old standby of if (CurrentBar == 0).

      Have you ever heard what the deal is with OnStartUp()? At the time I posted, I had restarted several times to no avail and then one restart more and suddenly it worked as expected. As I mentioned in my original post I have had the issue before and the common denominator in both cases was a custom dll I had written (I did target .NET 3.5)

      Intermittent errors of that nature make me very reluctant to use this in a production environment.

      Comment


        #4
        Hello Scott,

        OnStartUp() is called in the same method/order that it would be from a Strategy to an Indicator. Using custom dll's you may want to make sure that you have the latest updates for the .NET 3.5 Framework by running windows updates to prevent any issues.

        Alternatively, you may want to check to see if there is any errors inside of Initialize() as if there was a failure inside of Initialize() then OnStartUp() would not have the chance to run yet.
        JCNinjaTrader Customer Service

        Comment


          #5
          JC,

          I have the latest updates although I normally use .NET 4 and there are no errors in Initialize(). This is a bug in NinjaTrader that has been around for awhile. This problem has been mentioned by others in other posts/threads as well.

          When Print statements weren't executing, I went through the painful process of using the VS debugger. Sometimes Initialize() would be executed several times (expected behavior but never have been clear why it is done that way internally) but it was always executed at least one.

          OnStartUp() on the other hand was at times almost random. No execution, restart, over and over and over and suddenly it would work. That often points to a threading or some other sort of synchronization issue.

          Hopefully NinjaTrader 8 will fix the issue.

          Best Regards,
          Scott

          Comment


            #6
            Hello Scott,

            Are you using any custom resources that you are calling/referencing inside of Initialized()?

            Also you will want to use .NET 3.5 for NinjaScript.

            Happy to be of further assistance.
            JCNinjaTrader Customer Service

            Comment


              #7
              JC,

              Here is my Initialize() code

              Add(PeriodType.Tick, 1);

              CalculateOnBarClose = true;
              AutoScale = false;
              DrawOnPricePanel = true;
              Overlay = true;

              No custom resources and I use .NET 3.5 as my target for dll's that are used by NinjaTrader (.NET 4 dll's will give you an immediate error).

              I have had this issue with other dll/strategy combinations and from what I can gather, other developers have had this issue as well.

              Best Regards,
              Scott

              Comment


                #8
                Hello Scott,

                Can you send a toy* NinjaScript code replicating the behavior so that I may look into this. You can Export it as a Source File using the step from our Help Guide at the link below.


                You may send the file to Support [at] NinjaTrader [dot] com. Please reference this thread in the email.

                Happy to be of further assistance.

                *Toy - basically a stripped down version of code that isn't necessarily the whole logic; making it easier to identify lines of code.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  JC,

                  The code is so tightly integrated that it would be very difficult to do that. It only appears to happen in Market Replay mode and even then it is sporadic. I know those are the most difficult bugs to track down.

                  I will just try to keep my debugging limited to when the market is open; I need to take more time off on the weekends anyway.

                  Best Regards,
                  Scott

                  Comment

                  Latest Posts

                  Collapse

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