Replacing pending orders

Hi,can you please explain to me how I can do the following:

When a pending order is hit(turned into a market order),how to place another pending order in a fixed pip range away from it?

for an example,if a buystop is hit,place a sellstop order 20 pips below it,when the sellstop is hit place a buystop 20 pips above it,and so on.

Thank you.

Nobody can help me?..