My logic is explained below. Kindly let me know the code for he same.
Buy on the previous day’s high. Stop loss for Nifty is 30 points. If it moves in the direction of the trade, then the stop loss moves to the previous day’s low or 30 pts which ever is lower. Similarly for Short positions as well.