RSI Divergence code for PI


I want to get code for RSI Divergence, Buy Singal- when price are making higher high & RSI is making lower High.

Sell Signal- when price are making lower low & RSI is making Higher Low.

tried to find out everywhere, help on this will be much appreciated.

I am also in need of a similar code. Unable to get it. I just need to know how to compare two troughs and peaks in ‘trade script’ so that I can code it myself. could not find that one function