Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Comparing Volume from the Same Time of Day

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

    Comparing Volume from the Same Time of Day

    Hi,

    I'm trying to build an indicator which gathers volume data to compare to the closing bar, but the catch is that I only want to compare volume from the same time of day. Since volume varies throughout the day, I don't want to compare a bar in an after hours session to a regular market session because the comparison is not valid.

    i.e. volume at 12 AM should be compared to volume in prior session at 12 AM

    I tried to do it like this, but it didn't work. I need to get an array of volumes with 30 or more elements from the same time of day. The main problem seems to be an inability to grab Time[i] for N bars back.

    double[] volume = new double[30];

    if (CurrentBar > 30)
    {
    for (int i = 0; i < 30; i++)
    {
    if (Volume[i] > 0 && Time[i].ToShortTimeString() == Time[0].ToShortTimeString())
    {
    volume[i] = Volume[i];
    }
    }
    }

    #2
    How about doing a simple date subtract? I am assuming you want the volume 24 hours ago.

    VOL()[CurrentBar - Bars.GetBar(Time[0].AddHours(-24))] will get you the volume from the bar 24 hours ago. Will not work on Mondays or if you do not load more than a day's worth of historical data.

    Hope it helps.
    Last edited by praiz; 03-14-2012, 08:02 PM.

    Comment


      #3
      Thank you!

      I got your solution to work. This code will look back the required number of bars to get 30 data points and only compares volume from the same time of day. Only negative is that I have to load quite a bit of data for it to work.

      if (CurrentBar > (380 / BarsPeriod.Value)*31)
      {
      for (int i = 1; i < 1000; i++)
      {
      if (VOL()[CurrentBar - Bars.GetBar(Time[0].AddHours(-24*i))] > 0)
      {
      volume[counter] = VOL()[CurrentBar - Bars.GetBar(Time[0].AddHours(-24*i))];
      counter = counter + 1;

      if (counter == 30)
      {
      break;
      }
      }
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      597 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      555 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X