Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need OnTimer

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

    #16
    Initialize() is called one time per instantiation. But your object (when selected from the indicator/strategy list) is instantiated several times, and you can't control that by a flag.

    An indicator always starts at bar zero, but a strategy does not. I guess this is the problem you have with the NT code example.

    To perform a proper runtime initialisation with a strategy I use the following approach:

    privatebool runtimeInit;
    ...
    protectedoverridevoid OnBarUpdate()
    {
    if (FirstTickOfBar)
    {
    if (!runtimeInit)
    {
    ... your initial code ...
    runtimeInit = true;
    }
    }
    }

    This is the only way to initialize your timer properly within a strategy I personally know of.

    Regards
    Ralph

    Comment


      #17
      Ralph, thank you for your help. I'll check it a bit later and let you know.

      Regards,
      Eugene.

      Comment


        #18
        Ralph, as I noticed it did not help. If not set MaxProcessedEvents to some huge value system will stop soon. Try check your self.

        In init on/off MaxProcessedEvents = 32768;

        Regards,
        Eugene.

        Comment


          #19
          I'll give it a try, maybe not today but somewhen the next days.

          Regards
          Ralph

          Comment


            #20
            This is what I do:

            2. _timer.Start only called in OnBarUpdate

            hence after Initialize


            Thank you Ralph for making things clear!

            andreas

            Comment


              #21
              Originally posted by zweistein View Post
              2. _timer.Start only called in OnBarUpdate

              hence after Initialize
              This solution makes sense for me, because only fully functional instances (those how reach OnBarUpdate() get the chance to activate the timer.

              Regards
              Ralph

              Comment


                #22
                Hi Eugene,

                did run a test with your strategy which you provided with your first file. I applied WRITER to 5 different charts and run it for 45 minutes. No error messages. And that makes sense because you instantiate your timer with a static variable one time. But I was not able to close the strategies because that causes a crash. Here is the error message:

                16.09.2009 13:57:45|3|128|Error on calling 'Dispose' method for strategy 'WRITER': Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

                The explanation is a native c# error message. It says you accessed an instance variable without an valid instance reference (propably a null-pointer).

                However, I could not reproduce the event limitation error message.

                Regards
                Ralph

                Comment


                  #23
                  I have been able to reproduce the "More than 100 subsequent user events" message. However, the market is closed right now so no non-user events are coming in to my strategy. I suspect that the error message will go away if I start my strategy while the market is in session.

                  Comment


                    #24
                    Alternatively you could use the simulated datafeed for testing.

                    Comment


                      #25
                      Originally posted by honvl View Post
                      I have been able to reproduce the "More than 100 subsequent user events" message. However, the market is closed right now so no non-user events are coming in to my strategy. I suspect that the error message will go away if I start my strategy while the market is in session.
                      It is confirmed that there is no such error while the market is in session.

                      Comment


                        #26
                        OnTimer and Send Order

                        After I have defined internal value MaxProcessedEvents to huge value my system does not stops during the trading session, but I have another problem now. When I try call EnterShortLimit or EnterLongLimit limit from my TIMER's MyCustomHandler NINJA system crashed with error missage: Object reference not set to an instance of an object.The same code called from OnMarketDepth works fine.
                        Where is the problem?

                        Regards,
                        Eugene.

                        Comment


                          #27
                          Eugene,

                          Usually that error happens when you don't check for null on your order. Please see this tip: http://www.ninjatrader-support2.com/...ead.php?t=4226
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #28
                            Josh, as I noticed - code the same... I moved it from Timer part to other and it works...

                            Comment


                              #29
                              That doesn't change the fact of the matter. You should always check for null references first.

                              Also, please provide the full code version you are using now. We are shooting in the dark without it.
                              Josh P.NinjaTrader Customer Service

                              Comment


                                #30
                                I have attached a stripped down strategy which prints text to the output window every 1 second. The code is based on the example provided by NinjaTrader located at


                                In an indicator, the Timer works fibne, but in a strategy after +/- 2 minutes, I also get the "More than 100 subsequent user events" error message.

                                I tried the suggestions in this thread like calling _timer.Start in onBarUpdate
                                and making timer a static variable but I still get the same error.

                                did anyone find a solution for this for NT7 ?
                                Any help would be appreciated.

                                Marco
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

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