• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need method evaluated each second

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

    Need method evaluated each second

    Hello! If there's a way to evaluate some method exatly each second or more often? It's really important that strategy needs to work when nothing is changing and the OnBarUpdate is not evaluating. E.g. count pause time to in.

    Due to this page:
    https://ninjatrader.com/support/help...ick_replay.htm
    I understood that if I set "On each tick" update method then the functions OnBarUpdate and OnMarketData will be being evaluated each tick (as I know a tick should be evaluated 50+ times at a second). I write simple function that writes down in a file date time when it is evaluating. And the output of both OnBarUpdate and OnMarketData are similar:

    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:18
    27.03.2017 15:35:22
    27.03.2017 15:35:23
    27.03.2017 15:35:23
    27.03.2017 15:35:24
    27.03.2017 15:35:24
    27.03.2017 15:35:24
    27.03.2017 15:35:24
    27.03.2017 15:35:25
    27.03.2017 15:35:26
    27.03.2017 15:35:26
    27.03.2017 15:35:26
    27.03.2017 15:35:26
    27.03.2017 15:35:26
    27.03.2017 15:35:28
    27.03.2017 15:35:29
    27.03.2017 15:35:29
    27.03.2017 15:35:29
    27.03.2017 15:35:29
    27.03.2017 15:35:29
    27.03.2017 15:35:30
    27.03.2017 15:35:30
    27.03.2017 15:35:30
    27.03.2017 15:35:30
    27.03.2017 15:35:30
    27.03.2017 15:35:30
    27.03.2017 15:35:32
    27.03.2017 15:35:35
    27.03.2017 15:35:35
    27.03.2017 15:35:35
    27.03.2017 15:35:35
    27.03.2017 15:35:35
    27.03.2017 15:35:37
    Look, this functions are evaluated several times at some seconds but they pass some second. For example this function wasn't evaluated on 19th, 20th, 21th, 27th, 31th, 33th, 34th and 36th seconds. I need each second. So how can I achieve this?
    Last edited by Defake; 03-27-2017, 05:01 AM.

    #2
    Originally posted by Defake View Post
    Hello! If there's a way to evaluate some method exatly each second or more often? It's really important that strategy needs to work when nothing is changing and the OnBarUpdate is not evaluating. E.g. count pause time to in.

    Due to this page:
    https://ninjatrader.com/support/help...ick_replay.htm
    I understood that if I set "On each tick" update method then the functions OnBarUpdate and OnMarketData will be being evaluated each tick (as I know a tick should be evaluated 50+ times at a second). I write simple function that writes down in a file date time when it is evaluating. And the output of both OnBarUpdate and OnMarketData are similar:

    Look, this functions are evaluated several times at some seconds but they pass some second. For example this function wasn't evaluated on 19th, 20th, 21th, 27th, 31th, 33th, 34th and 36th seconds. I need each second. So how can I achieve this?
    Setup and use your own timer to handle things every second.

    Comment


      #3
      To build off kogonam's answer, here is a code sample from the help guide. We are happy to help with any specific questions that come up.

      Code:
      // http://ninjatrader.com/support/helpGuides/nt8/en-us/triggercustomevent.htm
      protected override void OnBarUpdate()
       {
          // OnBarUpdate() only runs as bars are processed, which is not guaranteed to occur at a specific interval
          // e.g., even on a 5 second bar series, there may be time periods where there are no updates due to low trading activity
          // or could be buffered due to running Calculate.OnBarClose. Instead of trying to obtain the Close[0] value
          // at some interval here, we are going to do it in our custom TimerEventProcessor
       }
       
       // This is the method to run when the timer is raised.
       private void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
       {
          // Do not process your code here but instead call the TriggerCustomEvent() method
          // and process your code in the custom handler method e.g., our custom PrintThePrice()
          // Doing so ensures all internal indexers are up-to-date
          TriggerCustomEvent(PrintThePrice, Close[0]);
       }
       
       // Print the latest closing price with the current time
       private void PrintThePrice(object price)
       {
          Print("The Last Bar's Closing Value as of " + NinjaTrader.Core.Globals.Now + " was " + price);
       }
       
       private System.Windows.Forms.Timer myTimer = new System.Windows.Forms.Timer();
       
       protected override void OnStateChange()
       {
          if(State == State.SetDefaults)
          {
              Name = "SampleTriggerCustomEventTimer";
          }
          else if(State == State.Configure)
          {
              // Adds the event and the event handler for the method that will
              // process the timer event to the timer.
              myTimer.Tick += new EventHandler(TimerEventProcessor);
       
              // Sets the timer interval to 5 seconds.
              myTimer.Interval = 5000;
              myTimer.Start();
          }
       
          else if(State == State.Terminated)
          {
              // Stops the timer and removes the timer event handler
              myTimer.Stop();
              myTimer.Tick -= new EventHandler(TimerEventProcessor);
          }
       }
      Last edited by NinjaTrader_JessicaP; 03-27-2017, 11:35 AM.
      Jessica P.NinjaTrader Customer Service

      Comment


        #4
        Okay I made this with DispatcherTimer. Everything is working, thanks!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by D Trader, Yesterday, 09:43 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cassiano_sanches, 07-10-2020, 07:37 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by terminatorT1000, 07-10-2020, 06:40 PM
        2 responses
        27 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Giudiver, 07-10-2020, 04:29 PM
        2 responses
        16 views
        0 likes
        Last Post Giudiver  
        Started by rtwave, Today, 04:11 PM
        0 responses
        4 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Working...
        X