Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnTimer event

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

    OnTimer event

    Is there an OnTimer event in NT? If not is there a work around? Thanks.

    #2
    You can use the following method TriggerCustomEvent() and then you can use standard .NET System Timer class.

    RayNinjaTrader Customer Service

    Comment


      #3
      Got it. Thanks a lot!

      Comment


        #4
        Originally posted by NinjaTrader_Ray View Post
        You can use the following method TriggerCustomEvent() and then you can use standard .NET System Timer class.

        http://www.ninjatrader-support.com/H...stomEvent.html
        I find this help entry to be confusing, since the Syntax section for TriggerCustomEvent shows that the TriggerCustomEvent method can have either 2 or 3 arguments, whereas the Examples section gives an example with only 1 argument.

        Comment


          #5
          Thanks for the feedback KBJ, please also review this reference sample using the TriggerCustomEvent() - http://www.ninjatrader-support2.com/...ead.php?t=5965

          Comment


            #6
            Sorry, I forgot to mention that I had already done that.

            What I noticed was that the reference sample does not match the example given in the help.

            When I implemented code in a fashion matching the reference sample (instead of matching the help example), I found that the code consistently aborted giving me a repeating message stating that NinjaTrader had to be restarted.

            That was the point that I backed out the use of TriggerCustomEvent and made my earlier posting, hoping that the help would be fixed and elaborated on.

            By the way, when the help is fixed, can this be posted somewhere that we can access it online, without having to wait for the next NinjaTrader update?

            Comment


              #7
              Not sure I follow KBJ. Are you saying the reference sample crashed NT?
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                No, what I'm saying is that I had trouble with code that I wrote which looked like this....

                Code:
                private void OnTimer(object sender, EventArgs e)
                {
                  TriggerCustomEvent( new CustomEvent( TimerSynchronized ), 0 );
                  timer.Enabled = false;    // Done with the timer.
                }
                
                private void TimerSynchronized(object obj)
                {
                  Special_Timer_Flag = true;
                }
                I realize that this is not what's in the help, and it's not what's in the reference sample either. I'm confused because the help and the reference sample conflict with each other.

                I notice that the reference sample doesn't mention "CustomEvent" at all, so does this mean it's obsolete?

                Could someone who's familiar with Ninja internals please document what the parameters are supposed to be for "new CustomEvent()" and how these parameters are supposed to be used?

                Comment


                  #9
                  KBJ,

                  Not sure why you think they conflict. They are inline with each other and will work as advertised.

                  new CustomEvent(MyCustomHandler, 0, "myText")
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Josh View Post
                    Not sure why you think they conflict. They are inline with each other and will work as advertised.

                    new CustomEvent(MyCustomHandler, 0, "myText")
                    The help for TriggerCustomEvent says:
                    Code:
                    [B][COLOR=Sienna]Examples
                    [/COLOR][/B]...
                    TriggerCustomEvent(new CustomEvent(MyCustomHandler, 0, "myText"));
                    Thus, there is one argument to TriggerCustomEvent in that example, which is:
                    Code:
                    new CustomEvent(MyCustomHandler, 0, "myText")
                    The syntax shown for TriggerCustomEvent in the help description shows 2 or 3 arguments:
                    Code:
                    [B][COLOR=Sienna]Syntax [/COLOR][/B]
                    TriggerCustomEvent(CustomEvent customEvent, object state)
                    TriggerCustomEvent(CustomEvent customEvent, int barsIndex, object state)
                    and the reference sample uses 2 arguments:
                    Code:
                    TriggerCustomEvent(MyCustomHandler, myTimer.Interval);
                    See what I mean?
                    Last edited by KBJ; 12-18-2008, 10:14 AM.

                    Comment


                      #11
                      I see. Disregard the Syntax portion and just go with what you see in either the Help Guide example or the reference sample.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        I'm still confused, as the Help Guide example (1 argument, undocumented syntax) disagrees with the reference sample (2 arguments).

                        Comment


                          #13
                          KBJ,

                          Disregard trying to correlate the two into one overload. Just call your CustomEvent and pass the object afterwards. Easiest to just follow the reference sample.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            TriggerCustomEvent

                            When I call:
                            TriggerCustomEvent(MyCustomHandler, myTimer.Interval);
                            as listed in the SampleCustomEvents.cs example, I get a compiler error:

                            Strategy\drawtest1.cs No overload for method 'TriggerCustomEvent' takes '2' arguments CS1501 - click for info 57 4

                            Also, using:
                            TriggerCustomEvent(new CustomEvent(MyCustomHandler), e);
                            gives the same error.

                            TriggerCustomEvent(MyCustomHandler, 1, "message");
                            compiles, but MyCustomHandler is never called. I know from debugging that TriggerCustomEvent *is* called.

                            Can you tell me which invocation I should be trying to use? I expect I'm making an error somewhere, but am confused by the differences/conflicts in the examples and in the documentation.

                            Thanks.

                            Comment


                              #15
                              My apologies, but of course not long after I posted my message, I tried something that finally worked. I called:

                              TriggerCustomEvent(new CustomEvent(MyCustomHandler), BarsInProgress, 1);

                              Apparently, it is important to pass in the correct 'BarsInProgress' value.

                              Also, note that you can also call:
                              TriggerCustomEvent(MyCustomHandler, BarsInProgress, 1);

                              If I could find documentation on CustomEvent, I might be able to figure out why that is.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              93 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              48 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              31 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              34 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              69 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X