Trailing stop algorithm

 
Hey guys,
does anyone of you have a reliable trailing stop algorithm you use in your experts (with error handling and optimized - not sending a new OrderModify for each profit increase) so that I do not have to reinvent the wheel? Would be much appreciated, others might find it useful as well.

Thanks a lot ;)

Jan