First your code has syntax error - unbalanced parentheses in ApplyStop statement.
BuyPrice - Ref ( LLV ( Low, 5 ), // THIS IS UNBALANCED
Secondly you don’t understand that how volatile works, see:
Without that flag it “samples and holds” the amount on ENTRY bar, but with “volatile” flag it uses current (bar by bar) value of amount. Your amount is written as
BuyPrice - Ref ( LLV ( Low, 5 )
But above in your code you defined BuyPrice as
BuyPrice = Close;
So your stop amount is just
Close - Ref ( LLV ( Low, 5 ), ????)
which means that you are using just CURRENT CLOSE, not close at the buy bar.
You really need to learn how to understand your own coding and get the insight into what you really calculating, see this: