It was my mistake, Tomasz, that I did not say that there can be any number of bars between any 2 signals. That I should have added in my problem statement. Because signals are not coming up on consecutive bars.

So, let's say:

we had a Short signal

After "n" bars we get a Buy signal

And "x" bars after Buy of step 2, we receive another buy signal
("n" and "x" are unknown and vary)
We go LONG on Step 3 completion.

Thanks for your time. Really appreciate all the guidance. I have started to learn FOR loops for this problem. Always get stuck in such situations.

@awilson@Tomasz thanks You guys rock. And, thanks a lot for your time. Really appreciate it. Hopefully, I will be able to come up with better problems/ questions next time.