Trailing stop loss using ApplyStop and LLV(L, 2)

I am trying to get some code working for a trailing stop loss that uses LLV(Low, 2) for the stop.

Applystop : Volatile = True

The below does not seem to be working - any suggestions please.

Thank you.

LowPriceSL = Ref(LLV(L, 2), -1);
stopamount01 = (H - LowPriceSL)+TickSize;
stopamount = Max(TickSize, stopamount01);
ApplyStop(stopTypeTrailing, stopModePoint, stopamount, 1, True);

Everything works in AmiBroker. Just use correct formula, see: http://www.amibroker.com/kb/2014/10/17/using-price-levels-with-applystop-function/

I saw that article. It looks like it's for a fixed stoploss set on entry - is that correct?

I am trying to use a volatile trailing stop - initially set using LLV(L,2) and then raised each bar using LLV(L,2) until the stop is triggered.

Don’t use applystop(), just put a cross() or C < in your sell/cover variable.

Thanks, I have used them in the past.

I was trying to get it working using applystop as it seems so neat and fast.

Volatile stops use same logic. And they work. Perfectly. But you need to understand your own formula. Specifically you need to know that LLV would be running (moving) and your stop will vary and you need to be aware of actual amount each bar. To do so use advice given here: How do I debug my formula? and use exploration as advised. Besides your stop amount in your formula depends on current bar High which is of course future leak (you don't know high until bar completes). You need to fix that first.