I see apparent errors, but DdlV is right: debug the script. If it does not work, asking on the forum is silver, but finding it out yourself is gold. Debug a script even if it seems to work.

Your "TradeIsLong" and the other TMF variables make no sense here. You probably looked on the wrong page in the manual. Probably you wanted to use trade statistics variables such as "NumOpenLong".