How to look several bars back.

 

If I want an EA to look back say 50 or 100 bars back for divergence, is it possible? Or do I have to compare the last closed bar with each of the prior 49 bars?

Thank you.