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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    152 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    89 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    131 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    127 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X