Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Bar Type erroneous value out of order

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

    #16
    Thanks habibalex.

    The "bad tick" that appears on this bar is entered from your BarsType logic. When debugging BarsTypes, it is important to have prints added before every call to UpdateBar and every call to AddBar to see exactly how your BarsType is building its bars.

    To look into this further, I suggest adding prints to show exactly what is being entered in each UpdateBar and AddBar call before that call is made. I suggest noting the line in which the call is made, as well. (Since I added print lines to the script in my example prints, these numbers will not be in line with yours.)

    I.E.

    Code:
    Print(string.Format("Update Bar (92): Time: {0} H: {1} L: {2} C: {3} Added V: {4}", time, barHigh, barLow, lastPrice, 0));
    UpdateBar();
    
    ...
    
    Print(string.Format("Add Bar (95): Time: {0} O: {1} H: {2} L: {3} C: {4} Added V: {5}", time, open, open, open, open, volume/4));
    AddBar();
    After running the BarsType to build the bar in question, we can then check for the last UpdateBar that updates the bar timestamp to see what values are updated to close that bar. We can then see the values used to update the bar for its closing values:

    Update Bar (136): Time: 6/19/2019 11:59:00 PM H: 2946 L: 2942.75 C: 2945 Added V: 16
    Update Bar (92): Time: 6/19/2019 4:01:00 PM H: 2934 L: 2930 C: 2878 Added V: 0
    Add Bar (95): Time: 6/19/2019 4:01:00 PM O: 2930.75 H: 2930.75 L: 2930.75 C: 2930.75 Added V: 196
    This particular Close value is from your lastPrice variable. I suggest debugging your script further by adding the prints like I have so you see everything that goes into UpdateBar and AddBar, and then to track lastPrice further or modify the code so it behaves as you expect.

    Please let us know if we can be of further assistance.

    Comment


      #17
      Hi Jim,

      The problem I see is that there is some additional series being called out of order and it seems like maybe a different thread is being accessed to load redundant values that have been loaded already.. Please see the screenshot
      Attached Files

      Comment


        #18
        Hello habibalex,

        I did some more debugging and spoke with QA for further clarity.

        I should first suggest to set IsTimeBased to true in your script because it is based off of minute data.

        IsTimeBased - https://ninjatrader.com/support/help...stimebased.htm

        BarsTypes with historical data are processed in a thread pool, but are not developed with separate threads. We should not be confusing what we are seeing as the bars object being built with multiple asynchronous threads.

        There are known scenarios, like when we are over a roll date, where there will be multiple BarsRequests for the same chart. This results in OnDataPoint running for separate Bars objects, which then get merged with the Merge policy. Because there are multiple Bars objects being built, we will see prints that appear out of order.

        If you include bars.GetHashCode() in your prints, you will see that the out-of-order prints are not of the same bars object.

        When I add IsTimeBased = true and also print the hashcode, the print order is making more sense.

        Please let me know if I can assist further.

        Comment


          #19
          Thanks Jim that was the issue. I appreciate the time you took to solve this.

          Comment

          Latest Posts

          Collapse

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