Help me to come out of the trades (square off) by these 2 conditions

Please guide me for the applystop code or normal code for the below 2 conditions to square off the trades already entered by buy or short strategy execution. we should come out only if
1.loss is 10 points or more
2.for every 10 points profit, stopploss should be revised to 5 more points and so on till the stoploss is hit.