Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

look back period over month boundary

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

    look back period over month boundary

    look back period over month and year boundary

    I am looking for indexing bars from 4:00 PM at previous day to 1:00 AM today. I have no problem is doing it within a month. But I cannot find an automatic way to go over month boundary and year boundary by using DateTime methods/functions. Any suggestions?

    DateTime EndTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 1, 00, 00);

    DateTime StartTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day-1, Time[0].Hour+15, 00, 00);

    int LookBack = GetBar(StartTime) - GetBar(EndTime);

    #2
    binwang2,

    You need to create your own logic to address month changes and year changes. You have to check the day if its 1 then you can't just subtract 1 from it. You'll have to switch it down to the prior day.

    Instead of doing it like this you can try this.

    Code:
    DateTime someVariable = Time[0].AddDays(-1);
    Then you take someVariable and then make the time adjustments you wanted and then pass that into your GetBar().
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    174 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    329 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    252 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    355 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    182 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X