Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

date time question

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

    date time question

    Hi,

    I'd like to try to get volume of the same bar of yesterday's session using this piece of code:

    TimeSpan oneday = new TimeSpan(24, 00, 00);

    Print("\n" + Time[0].ToString());
    int barsAgo1 = Bars.GetBar(Time[0].Subtract(oneday));
    Print(Time[barsAgo1].ToString() +" " + Volume[barsAgo1].ToString());


    the output, that gets produced puzzles me a bit. It's the volume of the bar, but two weeks ago.

    13/04/2020 18:35:00
    30/03/2020 18:35:00 11201

    13/04/2020 18:40:00
    30/03/2020 18:40:00 8834

    13/04/2020 18:45:00
    30/03/2020 18:45:00 6992

    Any ideas, what is wrong?

    Many thanks.

    Thomas


    #2
    My guess would be
    Code:
    int barsAgo1 = CurrentBar - Bars.GetBar(Time[0].Subtract(oneday));

    Comment


      #3
      Hello td_910,

      Thank you for your patience.

      MojoJojo is right on the money here, you need to subtract the bar index of the bar you want from the bar index of the current bar to get its BarsAgo value to be used in getting the time and volume.

      Here's how I'd do this rather than setting up a new TimeSpan, although that works as well:

      Code:
                  DateTime onedayago = Time[0].AddDays(-1);
                  Print("\n" + Time[0].ToString() + " " + Volume[0].ToString()); 
                  int barsAgo1 = CurrentBar - Bars.GetBar(onedayago);
                  Print(Time[barsAgo1].ToString() +" " + Volume[barsAgo1].ToString());
      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Thanks for that. I must have been blind

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by varun12343, Today, 03:09 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by Lance El Camino, Yesterday, 04:14 PM
        2 responses
        25 views
        0 likes
        Last Post NT-Roland  
        Started by MatthewLesko, Yesterday, 11:13 PM
        1 response
        14 views
        0 likes
        Last Post NT-Roland  
        Started by kevinenergy, Today, 01:44 AM
        0 responses
        7 views
        0 likes
        Last Post kevinenergy  
        Started by jtrading82, Yesterday, 04:56 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Working...
        X