The function inside enterlong is for trade exit only, not (yet) for trade entry. For entering, just check if the price hits TEMA and then place a market order.