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.

      Comment


        #4
        Thanks for that. I must have been blind

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        557 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 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
        545 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