How to restrict the barcount to only intraday

Hi friends,
I am trying to compare the two arrays and count the number of times the condition is true for an intraday.I am using the below code.

Count=0;
for(i=0;i<BarCount;i++)
 {
   
   if (C[i]>O[i])
      {
        
        Count=Count+1;
      }

 }

In the above code the problem is "BarCount" is considering all the bars(I want to make it to consider only for today bars).
So i modified the code in the below way.

newday=Day()!=Ref(Day(),-1);
barss=BarsSince(newday)+1;
Count=0;
for(i=0;i<barss;i++)
 {
   
   if (C[i]>O[i])
      {
        
        Count=Count+1;
      }

 }

Then i am getting the error as " condition if, while, for statements has to be numeric or boolean type.You can not use array here.please use [] (array subscript operator) to access array elements " How to resolve the issue.
Much appreciate for your guidelines.

@Kum001
Numerous numbers of posts by you but still ....How do I debug my formula?

printf("\n barss: %g",barss);
for(i=0;i<barss;i++)   //is this logic correct.... in context what you want to code? 

use LastValue

1 Like

Your 2nd loop is incorrect. It is not done that way. And barss is an array not single number.

Most importantly you do not need any single loop!

dn = DateNum();
newday = dn != Ref(dn,-1);
barss = BarsSince(newday)+1;

Count = Sum(C>O, barss);

lastCount = LastValue(Count);

todayCount = IIf( dn == LastValue(dn), Count, Null);

// plot only today
Plot( todayCount, "todayCount", colorDefault, styleHistogram );

Less code and multiple times faster.

Don't use loop here.

5 Likes