Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SessionIterator + IsFirstTickOfBar problem

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

    SessionIterator + IsFirstTickOfBar problem

    Hello,

    I use SessionIterator a lot in my trading tools and have noticed that when I combine it with base.IsFirstTickOfBar and base.Bars.IsFirstBarOfSession, it is getting called when it should not be. I am doing several if checks, see below.

    Code:
    if (this.sessionIterator != null)
    {
        if (base.IsFirstTickOfBar && base.Bars.IsFirstBarOfSession)
       {
          if (this.sessionIterator.GetNextSession(base.Time[0], true))
          {
             this.sessionHighPrice = double.MinValue;
             this.sessionLowPrice = double.MaxValue;
          }
       }
    }
    Reproducing the error:
    - I was using market replay data for ES 09-20 on 8/3
    - Trading hour CME US Index Futures RTH
    - 8 Renko bars
    - 09:30:01, first bar prints, no problems, base.IsFirstTickOfBar is false base.Bars.IsFirstBarOfSession is still true (makes sense)
    - approximately 09:30:27 plus or minus a few seconds, the second bar prints, base.IsFirstTickOfBar && base.Bars.IsFirstBarOfSession are both true again (I believe incorrectly)

    Problem 1:
    I know some bars use the internal remove last bar which I believe Renko bars do as well. However, the IsFirstBarOfSession should not return true but it does.

    Problem 2:
    Exactly when this happens, Close[0], Low[0] are both set to 3263.75 which is not a valid print anywhere in the orderbook during that moment. It appears to be exactly the low/closing of the previous session 7/31. The actual low price at the moment was 3281.25 plus or minus a few ticks but nowhere near the 3263

    Entire solution code available here on GitLab. The JDT.NT8.Indicators mid price indicator (non sharpdx version) or JDT.NT8.Indicators.Demos DemoSessionIterator are probably the easiest to reproduce with but any which use this mechanism exhibit the same behavior. Either of those could be copy/pasted into the NinjaScript Editor and compile straight away or the solution will place the JDT.NT8.dll in the bin/Custom folder and picked up when NT8 starts (then in Visual Studio attach to process and set breakpoints).

    Like I mentioned, I use this a lot so I'm very interested to see any pointers toward a solution or maybe a bugfix started.
    Last edited by jasonnator; 09-08-2020, 09:50 PM. Reason: add tags

    #2
    Hello jasonnator

    Thanks for the post.

    Problem 1:
    I know some bars use the internal remove last bar which I believe Renko bars do as well. However, the IsFirstBarOfSession should not return true but it does.
    For the IsFirstBarOfSession we would need additional details from that time such as the CurrentBar index to know if that was just a tick in the same bar or a new bar, you could try adding a print to make sure a new bar is being used or the same is being used. The IsFirstTickOfBar should be true if you are using a bars type with RemoveLastBar like renko uses.

    Note: If a bar type is set up to remove the last bar on a chart, IsFirstTickOfBar will automatically be set to True.
    https://ninjatrader.com/support/help...ttickofbar.htm

    Problem 2:
    Exactly when this happens, Close[0], Low[0] are both set to 3263.75 which is not a valid print anywhere in the orderbook during that moment. It appears to be exactly the low/closing of the previous session 7/31. The actual low price at the moment was 3281.25 plus or minus a few ticks but nowhere near the 3263
    I couldn't really comment here without being able to test and see this on my end. I opened the link you provided however that appears to be a whole visual studio solution. I did not see a test for this in your solution and would not be able to try and extract a sample from that. We can work with a more simple test .cs file if you want to make a specific test for your question. Generally for samples of an issue or to help demonstrate something I would suggest to make a new empty indicator and put only the relevant code in that file, then attach only that .cs file.

    I look forward to being of further assistance.

    Comment


      #3
      Please see the attached .cs file and the screen capture showing what I have described above.

      Jason
      Click image for larger version

Name:	Capture.PNG
Views:	515
Size:	118.0 KB
ID:	1117691
      [ATTACH]n1117690[/ATTACH]

      Comment


        #4
        Hello jasonnator,

        Thanks for the additional details.

        From the image and the code that looks to be expected. You are using OnEachTick, the realtime bar which is the last 3 prints shows the same bar index. That would indicate 3 ticks in the same bar. If you are using Renko bars then both properties should be true there. It was 3 ticks in the first bar of the session and IsFirstTickOfBar is always true with renko bars.

        I look forward to being of further assistance.

        Comment


          #5
          IsFirstTickOfBar I understand why that is true but I am also check with and logic for whether the current bar is the first bar of the session. If you look at the screen capture, it is returning true at least on two different ticks for the 2nd bar if the session. I have stepped through this tick by tick with the debugger attached and do not believe it is functioning properly

          I think the culprit is with Bars.IsFirstBarOfSession returning true when it should not. If when removing the last bar, setting that boolean is not an atomic operation or a lock is not used, this exact behavior is possible which should be an easy fix for the NT8 dev team.

          Comment


            #6
            Hello jasonnator,

            I tried stepping through the print as you have described however what I am seeing is 3 ticks within the same bar like I had described in my last reply. The image you provided also supports that, the current bar is the same for each of the Prints indicating it was from the same bar. In general I would not expect this to be true only once when using OnEachTick processing, you will very likely see it true quite a few times.

            Please let me know if I may be of further assistance.


            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            650 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            370 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            109 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            574 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            577 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X