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

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 smartromain, 03-13-2024, 01:42 AM
    5 responses
    92 views
    0 likes
    Last Post AndreiBig  
    Started by Noerclou, Today, 04:55 AM
    0 responses
    4 views
    0 likes
    Last Post Noerclou  
    Started by llanqui, Yesterday, 09:59 AM
    2 responses
    17 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by ThoriSten, Today, 03:56 AM
    0 responses
    6 views
    0 likes
    Last Post ThoriSten  
    Started by PhillT, 04-19-2024, 02:16 PM
    3 responses
    25 views
    0 likes
    Last Post mangel2000  
    Working...
    X