Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.


    Kate W.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jaybedreamin, Today, 05:56 PM
    0 responses
    3 views
    0 likes
    Last Post jaybedreamin  
    Started by DJ888, 04-16-2024, 06:09 PM
    6 responses
    18 views
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by Jon17, Today, 04:33 PM
    0 responses
    1 view
    0 likes
    Last Post Jon17
    by Jon17
     
    Started by Javierw.ok, Today, 04:12 PM
    0 responses
    6 views
    0 likes
    Last Post Javierw.ok  
    Started by timmbbo, Today, 08:59 AM
    2 responses
    10 views
    0 likes
    Last Post bltdavid  
    Working...
    X