Rank the top 20 biggest ROC of HHV

I am trying to do the following:

Get al list of the tickers where Close is higher than the Highest High Value and then rank them according to ROC value.

I have followed the tutorial:


But I can't seem to get the HHV list first. It seems to me that there would be a simple way to filter out the HHV values from the initial list and then rank them based on ROC but can't seem to find it.

Should clarify a bit. Are you trying to just return an exploration or ranking for some backtest?

Close can’t be higher then the highest high value. It can be equal but your list will be very small.

Are you wanting the close to be the highest close over “x” bars?

It is for backtesting yes. For example i want to have the results of all stocks that have their close higher or equal than HHV(Close, X), but i want them ranked by ROC or something else.

Perhaps I’m missing something but from your description, having your hhv(close) in your buy filter and a simple PositionScore based of ROC would do it.

Thats what i have now, but from the backtesting results it seems that It just looks in the top (20) ranked ROC's and looks for tickers with HHV(Close). I first want a list of all HHV(Close) signals and then rank them based on ROC.

@kenmartens perhaps something like this can help get you started in the right direction,

Condition = C >= HHV( C, 50 );
Score = IIf( Condition, ROC( C, 100 ), 0 );

I tested your solution but still seems to be returning the wrong results. Keep shooting thow I will keep testing :slight_smile:

First, "SMS style" of writing is not good. You need to elaborate on what you really need and why you claim something is "wrong". Words like that are meaningless. Getting help requires precision in asking questions:

Secondly, use advice given here:


Sorry for the SMS Style of writing.

The solution was actualy in the tutorial i followed all along:


I just had to replace the categories with my HHV_ = HHV(C, 40) and at the end correct the score to:

score = IIf( rank <= 20 && HHV_ == 1, values, 0 );