How to count prices that are greater than this bar?

I want to count prices that are greater than this bar in the recent 100 bars,
and I see there are only 3 bars that fit this condition (greater than 15304),
but I don't know how to express Sum(C > close of this bar, 100),

so I try to use Sum(C > HHV_in_rcnt, 10)
to count the recent 10 bars as below (but it shows zero always):

// (1) Recent HHV(C, 10) = 15304;
// (2) Count prices that are greater than HHV_in_rcnt;
HHV_in_rcnt = HHV(C, 10); // or HHV(C, 1);
qty_gt_rcnt_HHV = sum(C > HHV_in_rcnt, 100); 
// the answer of qty_gt_rcnt_HHV is 0; Why?

Then I tried to type in the constant of the close price of this bar (15304):

// (1) Type in the constant of the close price of this bar (15304);
// (2) Count prices that are greater than 15304;
qty_gt_rcnt_HHV = sum(C > 15304, 100);  
// the answer of qty_gt_rcnt_HHV is 3; This is what I want.

Please help, Thank you very much! :smiley:

Hhv includes current bar value so think yourself about consequences. Obviously close today can’t be higher than close from today

1 Like

@alexlin with regards to the first part of your question,

It appears as though you want to rank the current bar's Close with the other Closing values of the past 100 bars.

function NumericRank( array, N ) 
{
  // by Tomasz Janeczko on the old Yahoo! forum
  pn = N - (N-1) * PercentRank( array, N-1 ) / 100;  
  return pn;
}

In this example output,
image

The output would tell you for example that the most recent close is the 5th highest in the past 100 (so 4 other Close's where greater than the current close).

And so in your initial example where you had 3 bars greater than your "15304" (which I am assuming is the current bar's Close), then your NumericRank should be 4.

5 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.