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

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 bmartz, 03-12-2024, 06:12 AM
      5 responses
      32 views
      0 likes
      Last Post NinjaTrader_Zachary  
      Started by Aviram Y, Today, 05:29 AM
      4 responses
      13 views
      0 likes
      Last Post Aviram Y  
      Started by algospoke, 04-17-2024, 06:40 PM
      3 responses
      28 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by gentlebenthebear, Today, 01:30 AM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by cls71, Today, 04:45 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X