Login Page - Create Account

Support Board


Date/Time: Thu, 27 Feb 2025 09:23:34 +0000



For time bars: function for num of bars per day, and num of bars since midnight?

View Count: 571

[2021-06-24 00:27:54]
marcovth - Posts: 61
Hello ...

Kind of basic, but I couldn't find it ...

For time bars only: is there a sc.function for the number of bars per day (based on the settings), and a sc.function for the number of bars since midnight for a particular index?

(So if you give an index of a bar 3 days ago, the function will calculate the number of bars from midnight three days ago up to that particular index)

Anyway, my goal is to calculate the average volume for each same bar at the same time of each day. In other words, the average volume for a bar going back each day, indexed by the number of bars since midnight (or otherwise the first bar of the days).
[2021-06-24 11:09:01]
Sierra Chart Engineering - Posts: 104368
We will see if we can put together a function for this quickly.
Sierra Chart Support - Engineering Level

Your definitive source for support. Other responses are from users. Try to keep your questions brief and to the point. Be aware of support policy:
https://www.sierrachart.com/index.php?l=PostingInformation.php#GeneralInformation

For the most reliable, advanced, and zero cost futures order routing, *change* to the Teton service:
Sierra Chart Teton Futures Order Routing
[2021-06-24 12:04:53]
marcovth - Posts: 61
Thanks a lot. This worked for me already ...

SCSubgraphRef AvgVolumePerIndex = sc.Subgraph[9];
SCFloatArrayRef SumVolPerIndex = AvgVolumePerIndex.Arrays[1];
SCFloatArrayRef nSumVolPerIndex = AvgVolumePerIndex.Arrays[2];
int MaxPerBarIndex=0;

  int TO=sc.IndexOfLastVisibleBar;
  int FROM=sc.IndexOfFirstVisibleBar-100;

  for(int n=FROM; n <= TO; n++){
    int nYear,nMonth,nDay,nHour,nMinute,nSecond;
    SCDateTime nDate = sc.BaseDateTimeIn[n];
    nDate.GetDateTimeYMDHMS(nYear,nMonth,nDay,nHour,nMinute,nSecond);
    int nLastMidNight=sc.GetContainingIndexForSCDateTime(sc.ChartNumber,nDate.SetDateTimeYMDHMS(nYear,nMonth,nDay,0,0,0));
    int PerBarIndex=n-nLastMidNight;
    //AvgVolumePerIndex[n]=PerBarIndex;
    if(sc.Volume[n]>0){
      SumVolPerIndex[PerBarIndex] = SumVolPerIndex[PerBarIndex]+sc.Volume[n];
      nSumVolPerIndex[PerBarIndex] = nSumVolPerIndex[PerBarIndex]+1;
    }
    if(PerBarIndex>MaxPerBarIndex)MaxPerBarIndex=PerBarIndex;
  }
  
  
  for(int n=FROM; n <= TO; n++){
    
    int nYear,nMonth,nDay,nHour,nMinute,nSecond;
    SCDateTime nDate = sc.BaseDateTimeIn[n];
    nDate.GetDateTimeYMDHMS(nYear,nMonth,nDay,nHour,nMinute,nSecond);
    int nLastMidNight=sc.GetContainingIndexForSCDateTime(sc.ChartNumber,nDate.SetDateTimeYMDHMS(nYear,nMonth,nDay,0,0,0));
    int PerBarIndex=n-nLastMidNight;
    
    if(SumVolPerIndex[PerBarIndex]>0 and nSumVolPerIndex[PerBarIndex]>0){
      AvgVolumePerIndex[n]=SumVolPerIndex[PerBarIndex]/nSumVolPerIndex[PerBarIndex];
    } else AvgVolumePerIndex[n]=0;
    
    pVolMA[n]=AvgVolumePerIndex[n];
  }
  
  for(int z=0; z <= MaxPerBarIndex; z++){
    SumVolPerIndex[z]=0;
    nSumVolPerIndex[z]=0;
  }
  

To post a message in this thread, you need to log in with your Sierra Chart account:

Login

Login Page - Create Account