Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsType Trim & Merge

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

    BarsType Trim & Merge

    I would like to better understand BarsType functions TrimStart, TrimEnd, and Merge. When are they called? What are the purpose of those functions?

    #2
    Hello aslane,

    These are undocumented so I cannot provide any details about these.


    From my understanding these are not NinjaScript tools intended for NinjaScript programmers to use.

    This thread will remain open for any community members that are using unsupported manipulations of these properties that would like to share.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Well, if I have defined a BarType, will NinjaTrader call these functions? If so, under what circumstances?

      I need to understand what the intention is, so I do not interfere with normal Ninja behavior.

      Comment


        #4
        Hello aslane,

        To prevent interfering with NinjaTrader create your own variables with unique names, that do not use any names that are already used in the BarsType namespace or in the script class.

        NinjaTrader does use these functions behind the scenes for string manipulation.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          When loading a chart with data via a bars type, typically more data is requested than is actually necessary. For example, using the SecondsBarsType with 30sec period and requesting just 1 day of data actually requests 3 days of data.

          For example, requesting 1 day of data on the 14 Feb, the data returned starts on 11 Feb session open:

          Click image for larger version  Name:	image.png Views:	0 Size:	29.6 KB ID:	1336692

          However, when the data transitions from historical to real-time, TrimStart and TrimEnd are called with numBars = to the actual number of requested bars:

          Click image for larger version  Name:	image.png Views:	0 Size:	39.5 KB ID:	1336693

          Notice​ the bars.Count and barsSeries.Count drops from 6208 to 3464.

          Having TrimStart and TrimEnd defined as virtual methods allows any custom data structures to be trimmed to match trimmed bars/bars series. For example the Volumes property on the VolumetricBarsType which is decalred as a VolumetricData[] array. Without this, the Volumes property would contain more elements than bars and the data would be 'miss-aligned'.

          Use TrimStart / TrimEnd in you own custom bar types to keep your own custom data structures aligned with the count of bars / bars series.

          It's still a bit unclear to me as to why there's a separate TrimStart and TrimEnd (instead of just Trim) but they do get called with different numBars values, so be sure to trim your custom data structures in both.
          Last edited by tcdouglas; 03-05-2025, 02:56 AM.

          Comment


            #6
            Hello tcdouglas,

            NinjaTrader automatically downloads data for the full day of the previous session prior to the first bar of the data request.
            The data is then distributed to any subscribers.

            Unfortunately, I cannot provide insight into the undocumented and unsupported internal properties.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            557 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            324 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
            545 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            547 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X