I've been trying to write a very simple TMF that would exit Long trades when the current price (tick) crossed below any kind of moving average, but am not having much luck.

I can't seem to find any examples of this in the manual, as these functions are generally more about trade management - i.e. amending stop losses.

I am using 30 minutes bars in run function, so, for now, I have added the below into the main code, however as this is only called once every 30 minutes, I can see in my back-testing there are many examples where the price has not only gone through the moving average but by the time this is called and actioned, it is a much greater loss than it would have been if the trade was closed as soon as the price went through the MA:

if(crossUnder(Prices,ALMA))
exitLong();

I've also looked into tick() and tock() but not having any joy there either.

Last edited by 1ND1G0; 02/13/21 20:25.