How to Code Tradescript for 3 Lower highs and 3 higher lows

Pls. help to Code in TradeScript in PI, to find 3 Lower highs and 3 higher lows alternatively for 20 period.

First appears H1 than L1 than H2 than L2 than H3 than L3 such that H1>H2>H3 (Lower highs) and L1<L2<L3 (Higher Lows)

Set H1=1st highest high Value, set H2= 2nd highest of high value, Set H3= 3rd highest of high Value like wise Set L1=Lowest low value, same way L2, L3. and if close above H3 than buy.

Highest High Value Returns the highest value of the high price over the specified number of periods.
Recommended Parameters
Periods: 21
Example

HIGH = HHV(21)

Evaluates to true when the high is the highest high in the past 21 bars.

Lowest Low Value Returns the lowest value of the low price over the specified number of periods.
Recommended Parameters
Periods: 21
Example

LOW = LLV(21)

Evaluates to true when the low is the lowest low in the past 21 bars.

2nd and 3rd highest highs or lowest lows can not be written in tradescript

Thanks for your reply, LLV & HHV i had already figured out . Isn’t there a round about way to it? Or can you help me code for forming symetric triangle? using Maxof or Max or something or loop function to check all values High vector and return 2nd highest ?

Thank you AlgoGeek,

I would like to add one more query here. I need to calculate HHV and LLV taking reference of 5 candle sticks back to the latest candle of one hour time frame.

please help how to use?

HIGH > REF(HIGH,5) OR
LOW < REF(LOW,5)