Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom BarsType: How to force tick processing starting at bars.FromDate

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

    Custom BarsType: How to force tick processing starting at bars.FromDate

    Hi Team,
    I'm developing a custom BarsType built from tick data. It needs to always start processing tick data from the session start time of the bars.FromDate date.
    The issue I'm encountering is that if there is cached bar data for the bars.FromDate date, all that tick data is skipped over and not processed.
    e.g. The following code produces the following output when there is cached bar data.

    Code:
    protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
    {
    if(runOnce) {
    Print(dir+".Count = "+bars.Count+" \t .FromDate = "+bars.FromDate+" \t\t time = "+time); // " \t time.Date = "+time.Date+ runOnce = false;
    }
    Output:
    .Count = 39 .FromDate = 2/22/2021 12:00:00 AM time = 2/25/2021 1:04:32 AM

    The barstype I'm creating needs to start processing tick data from 2/22/2021 4:00:00 PM, which is when the session begins. But, NT starts processing tick data at 2/25/2021 1:04:32 AM. How can this be done?
    Thanks.

    #2
    Hello zacharydw00, thanks for your post.

    The first data point is going to be determined by the session template that you have set on your chart. When I open an ES chart with the default session template the data starts at 4PM. Your print produces:
    .Count = 0 .FromDate = 2/28/2021 12:00:00 AM time = 2/28/2021 4:00:00 PM

    If you are making changes to a bar-type you must clear the cache when you re-compile. The cache can be found under Documents\NinjaTrader 8\db\cache; Please clear the cache before proceeding.

    I attached my test script to this post. This is simply a modification of the Tick bars type. The Tick bars type uses the session iterator to know when a new session had begun, not the time stamps from the bars object.

    Best regards.

    Attached Files
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,
      The issue I'm trying to prevent is having to clear the cache files before any bar processing begins. An example would be if a chart was created with the Data Series > 'Days to load' set to 15. Then later, the 'Days to load' is reduced to 10, I don't want to have to delete the cached data series files and invoke 'Reload All Historical Data' in order to force NT to start processing tick data from the bars.FromDate date.

      The Tick bars type uses the session iterator to know when a new session had begun,...
      I know about using the SessionIterator code. I left it out of my example intentionally, because it doesn't influence the issue. Also, ignore the time of day. That is not what this issue is about either.

      I'll rephrase the question again. How can NT be forced to ALWAYS (ignoring it's cached data series files) start processing tick data starting on the bars.FromDate date? As the Output in mu first post shows, when there is cached data series files NT will start processing tick data several days after the bars.FromDate date. That is the issue.
      Another way of looking at this is I always want the barstype code to start processing tick data with bars.Count at 0. If there are cached data series files then the code will start processing with bars.Count = 39 (for example, as my Output above shows). But, I need to code to ignore the existing cached bars so that it starts process from the bars.FromData date, not whenever the bars index 39 date is.
      Thanks.
      Last edited by zacharydw00; 03-03-2021, 05:07 PM.

      Comment


        #4
        Hello zacharydw00, thanks for your reply.

        There is no way to force NinjaTrader to not use the cached bar data. You will only need to clear out the cache data if changes are made to your bars type. Once the bars type has no more changes made to it, it can be applied to any chart. Please see the Tick bars type an exemplary tick-based bars type.

        Please let me know if I can assist any further.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hi Chris,
          Thanks for your example code. I ran it and here is the results...

          The initial application to the chart, with Data Series > 'Days to load' = 9, created this output
          Code:
          .Count = 0 .        FromDate = 2/23/2021 12:00:00 AM     time = 2/22/2021 4:00:00 PM
          if (bars.Count == 0) 2/22/2021 4:00:00 PM
          The code started processing from the session break datetime prior to the bars.FromDate.

          Then I changed Data Series > 'Days to load' to 5, and that created this output
          Code:
          .Count = 374      .FromDate = 2/28/2021 12:00:00 AM          time = 3/4/2021 4:00:00 PM
          Your code did not start process from the session break prior to the bars.FromDate.


          You will only need to clear out the cache data if changes are made to your bars type.
          I was not making any edits to your example code, but still your code requires the cache data to be deleted to start processing tick data from the bars.FromDate date.
          How can we get the bar code to always start processing tick data from the bars.FromDate date?

          Thanks.

          Comment


            #6
            Hello, thanks for your reply.

            I am getting matching times with my tests, from my most recent test:
            3/4/2021 12:00:00 AM
            3/4/2021 12:00:00 AM

            Can you run this new test script, I changed it slightly. If you see the same issue please tell me what instrument you are using so I can try the same thing. If you still see the issue please test using a new database. To make a new database:

            Close out of NinjaTrader
            Go to Documents\NinjaTrader 8
            Rename "db" to "dbOLD"
            Restart NinjaTrader and test again.

            You can revert this process by closing NinjaTrader, deleting the new "db" and renaming "dbOLD" to "db" then restarting NinjaTrader.

            I look forward to hearing of your results.
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bosajin, Today, 09:51 AM
            2 responses
            7 views
            0 likes
            Last Post bltdavid  
            Started by Newant, Today, 08:13 AM
            2 responses
            23 views
            0 likes
            Last Post Newant
            by Newant
             
            Started by alejandro888, Yesterday, 10:14 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by devro, Yesterday, 07:00 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by mr_trade, Today, 07:13 AM
            0 responses
            18 views
            0 likes
            Last Post mr_trade  
            Working...
            X