Getting highest high volume of last 5 green/bullish and last 5 red/bearish candles

Hi,

Can you please help me with my below query ?

I need to get the highest high volume out of the last 5 Green/bullish candles and last 5 Red/Bearish Candles

GreenCandle = C > O;
RedCandle = O > C;

GreenCandleVolume = IIf(GreenCandle , Volume, 0);
RedCandleVolume = IIf(RedCandle, Volume, 0);

How do I continue the above code to get me the the Highest High volume on last 5 Green and Red Candles?

I know we need to use HHV function, but how to get those last 5 green candles and red candles volumes because in the above arrays of GreenCandleVolume and RedCandleVolume there will be zeroes in between , so I need to take only the non-zero 5 candles.

Could you please help ?

Thanks in advance

I have not tried it but the following could work.

GreenCandle = C > O;
RedCandle = O > C;

GreenCandleVolume = SparseCompress( GreenCandle , Volume );
HHVGreenVolume = HHV( GreenCandleVolume, 5 ) ;
HHVGreenVolExpand = SparseExpand( GreenCandle , HHVGreenVolume ) ;

For red candle do it yourself.

5 Likes

Thank you @codejunkie , nicely done.