For seeing why your script does not work, the whole code would be needed. But the TMF already can not work this way. You're using the global Trail variable without setting it before, and you're sometimes setting TrailLock and sometimes not. Trailing won't work anyway without Stop. All this must be properly set up for entering a trailing trade. The TMF must also return a number, like 0 or another integer code, not a TRADE pointer. And you can't get a continous flow of positions when you're using stops or trailing.

If you want to enter a new position immediately when the old one is stopped out, you must handle stop and trailing only in the TMF. You can't use the global Stop/Trail variables for this because they won't enter a new trade.

Look in the manual about an example and return codes of a TMF:

http://manual.zorro-trader.com/trade.htm