Support Board
Date/Time: Thu, 27 Feb 2025 09:32:34 +0000
Post From: For time bars: function for num of bars per day, and num of bars since midnight?
[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; } |