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 DannyP96, 05-18-2026, 02:38 PM
        1 response
        85 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        143 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        83 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        257 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        334 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X