Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

First bar after rollover

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

    First bar after rollover

    Hi,
    I'm developing a class that shows rollovers on charts and do some other stuff. RolloverCollection has rollover dates but not times, (time in those dates are 12:00AM). By NT logic rollover "occurs" at first bar of trading session and NT uses prices from new contract. So how do I get this first bar? And have some logic when this bar occurs.

    Well, I can loop though all bars before processing bars OnBarUpdate (CurrentBar ==0), find when Bars.IsFirstBarOfSessionByIndex() is true and find nearest bar dates to my rollover dates. But it just sooo inefficient. I got 75 instruments, each has at least 80 rollovers, on 5 min chart for last 20 years... That's a crime against CPU time.

    Maybe there is better way? Any advice would be appreciated.

    #2
    Hello Leeroy_Jenkins,

    Thank you for your post.

    If you're using an ETH chart, the session begins on the day prior to the session date, so what you could do is to compare the current date to the rollover date minus 1 day, and if that matches use Bars.IsFirstBarOfSession to check whether it's the first bar of the session. (If you're using RTH charts, you'd want the dates to be equal).

    Here's an example:

    foreach(var rollover in Bars.Instrument.MasterInstrument.RolloverCollectio n)
    {
    Print(rollover.ContractMonth);
    Print(rollover.Date);
    Print(rollover.Offset);
    if (Time[0].Date == rollover.Date.AddDays(-1))
    {
    if(Bars.IsFirstBarOfSession)
    {
    BackBrush = Brushes.HotPink;
    }
    else
    {
    BackBrush = null;
    }
    }
    }

    This will paint the background for the first bar of the ETH session for the rollover date. Since we're just doing this in OnBarUpdate for the historical bars when it's iterating over them anyway, the CPU impact is fairly minimized once you've iterated over the historical bars.

    Please let us know if we may be of further assistance to you.


    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