No takers, so here the solution: You're setting trade parameters in function A for trades in function B, and vice versa - that is probably not what you intended.

Just as in real life, you must set stop, exit etc. _before_ entering a trade. When the trade is already entered, it's a little too late.