How about just a simple code: reverse trading strategy at LOSING stoploss. Here is example EA for one to modify.