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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    54 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    25 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    17 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    23 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    24 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X