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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    561 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    325 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
    547 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