Ok, it's clear that this script won't give you much joy. The computer just did what you told it to do. You're setting trade parameters to prices of a different asset.

I don't know why you do asset() calls in a TMF, but if you do, you must switch back the asset to the asset of the trade afterwards. Also don't tamper with trade variables unless you know precisely what and why you're doing that. If the purpose was just setting a trailing stop, there are several examples in the manual.