refactor calculate_stoploss

part 1, still need to fix the caller