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

Need OnTimer

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

    Need OnTimer

    Hi,

    I need OnTimer event. How I can do it in NINJA? Sure, you can advice me - use OnMarketDepth because it called offen, but I need pure Timer for strong each second system call.

    PS. Sorry found thread about timer already ...

    Regards,
    Eugene.
    Last edited by ELabunsky; 09-13-2009, 06:16 PM.

    #2
    I have found that it works fine for 1 system only. When I tried add another system sometime I have this error in log:

    14.09.2009 14:13:16 Strategy Error on triggering custom event for strategy 'WRITER': More than 100 subsequent user events

    And then system for prev. added instrument stopped.

    PS. I have attached the source code. I have tried static timer also, init in Init and OnBar - the same error. After some time - More than 100 subsequent user events error. For one active system also...

    PPS. Found that I can set MaxProcessedEvents prop. ... Set to 1000. Waiting when NT will stop. Why NT did not add simple OnTimer???...

    Regards,
    Eugene.
    Attached Files
    Last edited by ELabunsky; 09-13-2009, 11:26 PM.

    Comment


      #3
      Eugene, I believe this issues is with your custom code, can you please recheck and ensure there no infinite loop / recursion present in the script?
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Bertrand, enclosed code is working fine. I have fixed MaxProcessedEvents only. This is NT bug/feature - do not know how i say about it.
        Please, add to NT feature's list native OnTimer support.

        Regards,
        Eugene.
        Attached Files
        Last edited by ELabunsky; 09-14-2009, 05:38 AM.

        Comment


          #5
          Eugene,

          This is generally outside the scope of what we can offer support for as it is much more advanced C# programming. What you can take a look at is this reference sample though: http://www.ninjatrader-support2.com/...ead.php?t=5965
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            Eugene,

            This is generally outside the scope of what we can offer support for as it is much more advanced C# programming. What you can take a look at is this reference sample though: http://www.ninjatrader-support2.com/...ead.php?t=5965
            Josh, I used exactly this sample and this sample code stopped in NT. When I have fixed undocumented prop. (found info about it on this forum) it's working fine.
            I can't understand what about advanced in OnTimer?

            Regards,
            Eugene.

            Comment


              #7
              Eugene,

              Not sure what part of the sample does not work for you as it works fine here. Timer events are unfortunately outside the scope of what we can support.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Josh View Post
                Eugene,

                Not sure what part of the sample does not work for you as it works fine here. Timer events are unfortunately outside the scope of what we can support.
                Josh, I have noticed in my last post with attached source code that It's working fine with undocumented settings.
                OnTimer is default properties and should be released by default in NT.
                I guess best way report developer's team about this problem.

                Regards,
                Eugene.

                Comment


                  #9
                  Thank you for the suggestion. I have forwarded this to the developers.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello,

                    I remember that a timer in a strategy is more tricky than in an indicator.

                    How I did it:

                    1. _timer is a static variable
                    #Variables
                    static
                    System.Windows.Forms.Timer _timer=new System.Windows.Forms.Timer();

                    2. _timer.Start only called in OnBarUpdate

                    3. No Dispose() of _timer

                    4. in
                    TimerEventProcessor(
                    Object myObject, Eve...){

                    System.Windows.Forms.Timer ti= myObject as System.Windows.Forms.Timer;
                    // if you need it
                    }



                    I hope this helps

                    good luck
                    Andreas

                    Comment


                      #11
                      Originally posted by zweistein View Post
                      Hello,

                      I remember that a timer in a strategy is more tricky than in an indicator.

                      How I did it:

                      1. _timer is a static variable
                      #Variables
                      static
                      System.Windows.Forms.Timer _timer=new System.Windows.Forms.Timer();

                      2. _timer.Start only called in OnBarUpdate

                      3. No Dispose() of _timer

                      4. in
                      TimerEventProcessor(
                      Object myObject, Eve...){

                      System.Windows.Forms.Timer ti= myObject as System.Windows.Forms.Timer;
                      // if you need it
                      }



                      I hope this helps

                      good luck
                      Andreas
                      Andreas and you have not "More than 100 subsequent user events" stop problem with your code without additional trick? Did you develop trading system or indicator? May be you could send simple complete sample as I did it below?

                      Regards,
                      Eugene.

                      Comment


                        #12
                        no such a problem.

                        But if you have 100 user timer events in some queue then it look like your timer callback does not return back to the caller, hence the caller keeps the event in the queue.
                        I suspect some bug in your code that throws an exception in a place where it is not easy to see.

                        Comment


                          #13
                          this is NT bug. read my posts below and you will see - I have used undocumented feature and it works fine now. this is NT bug and if I'll call timer once per second NT stopped my system. only undocumented helped.

                          Comment


                            #14
                            Hi Eugene,

                            you should never initialize your timer in Initialize(), do that at runtime only (like the NT code example does). Every strategy and indicator object is initialized several times by NT. And therefore Initialize() is called several times. But only one of these instantiations "survives" the initial phase and starts to operate. And only for this instance you have the control over Dispose(). The other instantiations are destroyed by the garbage collector somewhen, and you don't have any control about how long these "zombies" are alive including your activated timers.
                            I don't think the problem you are describing is a NT bug.

                            Regards
                            Ralph

                            Comment


                              #15
                              Hi Ralh,
                              Thank you for advice. In Init I can init once if check some flag. NT sample is not correct (my systems did not start from 0 bar and I do not like find the bar where it can be started). But I tried init once - the same...
                              Regards,
                              Eugene.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by helpwanted, Today, 03:06 AM
                              1 response
                              5 views
                              0 likes
                              Last Post sarafuenonly123  
                              Started by Brevo, Today, 01:45 AM
                              0 responses
                              7 views
                              0 likes
                              Last Post Brevo
                              by Brevo
                               
                              Started by aussugardefender, Today, 01:07 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post aussugardefender  
                              Started by pvincent, 06-23-2022, 12:53 PM
                              14 responses
                              242 views
                              0 likes
                              Last Post Nyman
                              by Nyman
                               
                              Started by TraderG23, 12-08-2023, 07:56 AM
                              9 responses
                              384 views
                              1 like
                              Last Post Gavini
                              by Gavini
                               
                              Working...
                              X