Moving Stop losses during backtesting

Hi all,
does anyone know how to do this ? I want to use a max stop loss after opening a trade but once it goes into profit I want to move this stop loss to 50% of profits. Any idea how I can do this for back testing ?

Thanks,
David