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

Problem with realtime data procesing

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

    Problem with realtime data procesing

    Hello,

    I have a strategy which is doing some position checkup/management periodically. Basically, it is designed to be executed each time it receives new data from server, something like:

    protected override void OnBarUpdate()
    {
    if (Historical)
    {
    return;
    }
    Print("Executing at: " + DateTime.Now);

    //...
    doStuff();
    //...
    }

    Now, in principle, it is working fine for most of the time, however it appears to be some periods when it is not working properly since it is not receiving data anymore (so basically, not even the "Executing at: " gets printed).

    It's hard to exactly define these periods, appearantly each day a few hours before 00:00 GMT (possibly some platform unavailability time for maintenance activities? although it seems I can still submit orders etc. during these times).

    So currently I'm trying to figure out a workaround for this, and I am thinking of the following options:
    1. reconfigure the data connection? I noticed that if I use for instance the simulated data feed I still receive data even during these hours, so I was thinking to use it as a backup connection (but I haven't tested yet, don't even know if it might make sense);
    2. implement a workaround as to have some piece of code running periodically and calling my business logic (the "doStuff" method). However I am not sure of the best way to achieve this, since:
    - I think working with Thread.Sleep would not be advisable, if I understand correctly it would interfere with built-in event processing in Ninja Trader;
    - maybe using a Timer instead would be a better idea? (as it is described for instance here: https://ninjatrader.com/support/foru...-general-timer)

    What would you think it would be more appropriate from the above options? Any other ideas are welcome.

    Thanks,
    Sorin

    #2
    Your data connection is (mostly likely) perfectly fine.

    There are never platform/data unavailability issues due to scheduled maintenance when
    markets are open.

    You failed to identify the instrument you are trading. That seems like a pretty key thing to know,
    since certain less popular instruments have 'dead' periods of little activity (like, apparently, around
    00:00 GMT), some considerably more often than others.

    Some periods are deader than others. Why is this? Millions of reasons. You'll have to start a
    worldwide campaign to remind all the millions of traders to keep trading your pet instrument so
    you can get your ticks into your strategy. Relax, this is real-time -- so nothing happens according
    to plan -- and if your strategy is idle, it means no one is trading that instrument at that moment.

    As far as #1 --
    There is nothing to 'reconfigure'.
    Your instincts are correct, using the simulated data feed as a backup connection makes
    absolutely no sense whatsoever.

    As far as #2 --
    Use the timer option.
    You have the perfect use case for it.

    Good luck!
    Last edited by bltdavid; 05-13-2020, 12:10 AM.

    Comment


      #3
      Hello smf2005,

      Yes this could be cause for a variety of reasons. A timer is likely the best option if you have a task to execute at a specified interval no matter if there is data.

      - I think working with Thread.Sleep would not be advisable, if I understand correctly it would interfere with built-in event processing in Ninja Trader;
      You are correct, you never want to delay OnBarUpdate or your other events by using Sleep or while(){} as another example.

      The sample you linked to would be the suggested way to execute a timer, you can also find a sample in the TriggerCustomEvent page. To quickly expand on why that the trigger method is used, that is to make sure the NinjaScript properties have correct values when you are using a non NinjaScript event like a timer event. That can be used for timers or any type of event such as a button click event.

      I look forward to being of further assistance.

      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Segwin, 05-07-2018, 02:15 PM
      14 responses
      1,789 views
      0 likes
      Last Post aligator  
      Started by Jimmyk, 01-26-2018, 05:19 AM
      6 responses
      837 views
      0 likes
      Last Post emuns
      by emuns
       
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,293 views
      1 like
      Last Post jgualdronc  
      Started by Touch-Ups, Today, 10:36 AM
      0 responses
      13 views
      0 likes
      Last Post Touch-Ups  
      Started by geddyisodin, 04-25-2024, 05:20 AM
      11 responses
      63 views
      0 likes
      Last Post halgo_boulder  
      Working...
      X