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

Using a Timer Event

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

    Using a Timer Event

    Hi,

    I have a timer running that I want to use to give me info in the output window periodically, independent of the onbarupdate() method.

    The timer itself works fine, but when I try to access things like Count, CurrentBar etc the values returned are zero or -1.

    Is there something else I need to do to get the correct values?

    Thanks,
    Will.

    #2
    I found this thread, I see that code is not supposed to be put in the timer event.

    Comment


      #3
      Hi Will, that's correct - were you able to get it to work as you would expect when following the structure of the example?
      BertrandNinjaTrader Customer Service

      Comment


        #4
        no, not yet, I'm not sure if my event is being triggered. I have debug output inside the event handler, but nothing is printed.

        In the timer event I print output before the event handler call and after it, and both those are printed in the output window, but not the print() inside the event handler.

        I have written it like this - ("in trigger" is not printed)

        public void OnTimerEvent(object source, EventArgs e)
        {
        Print("before trigger");
        TriggerCustomEvent(wtaSetCursor, 0, checkCommandsTimer.Interval);
        Print("after trigger");
        }

        private void wtaSetCursor(object curCmd)
        {
        Print("in trigger");
        }

        Comment


          #5
          Will, are you working here inside an indicator or strategy and is this in historical or realtime / forward testing?
          BertrandNinjaTrader Customer Service

          Comment


            #6
            in an indicator, forward testing.

            Comment


              #7
              Thanks, here's a simple example working normally on my end, can you please give this a run to check? It will trigger in 2 second intervals and print the event trigger time to your output window then to confirm.
              Attached Files
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Ok thanks I will give that a go,

                Will.

                Comment


                  #9
                  Got it now thanks. I realised from your code that I was using System.Windows.Timers whereas you were using System.Windows.Forms.Timer.

                  This also solved my problem from below thread where I was trying to access the window handle from within the timer.




                  Will.

                  Comment


                    #10
                    Tried to download the .cs file attached in the Bertrand reply but it offers me attachment.php file instead.. I am using IE11.

                    Could you please attach it somehow differently?

                    Comment


                      #11
                      The file is attached correctly, I downloaded it myself again just to test.

                      I suggest there is some setup in your browser causing the problem, so try another browser.

                      Comment


                        #12
                        Hello maxima,

                        Thank you for your post.

                        If you would like I can send you the file directly. Please send a note to support[at]ninjatrader[dot]com with 'ATTN: Patrick - 907532' in the subject line and a reference to this thread in the body of the e-mail: http://www.ninjatrader.com/support/f...ad.php?t=60545

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by inanazsocial, Today, 01:15 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by rocketman7, Today, 02:12 AM
                        0 responses
                        10 views
                        0 likes
                        Last Post rocketman7  
                        Started by dustydbayer, Today, 01:59 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post dustydbayer  
                        Started by trilliantrader, 04-18-2024, 08:16 AM
                        5 responses
                        23 views
                        0 likes
                        Last Post trilliantrader  
                        Started by Davidtowleii, Today, 12:15 AM
                        0 responses
                        3 views
                        0 likes
                        Last Post Davidtowleii  
                        Working...
                        X