Please help me finding the code for RSI divergence ( hidden and Regular )

Can anyone please suggest me the entire code to fulfill these criterion
I need the code for only buy signal—

1).RSI(14) bearish hidden divergence has to give a buy signal( lower lows on RSI corresponding to Higher Lows in the main up trend)

3).RSI bullish regular divergence has to give a buy signal ( higher lows in RSI corresponding to the lower lows in the down trend )

4).have to detect Range bound conditions in market

5). Bollinger band condition for buy signal

I know there are functions to calculate the ’ Higher Highs ’ and ’ Lower Lows ’ in Tradescript… But
what about these ’ Higher Lows ’ and ’ Lower Highs ’

any suitable suggestions would be greatly appreciated