Volatile Trailing Stop with ApplyStop


#1

I have tested the ApplyStop with and without Volatile parameter. The backtest results are doubted with Volatile is True. The Trailing Stop was triggered correctly, but the exit was not delayed to next bar Open.
It was sold on Open on the same stop date.

My code is as below.

SetBacktestMode ( backtestRegular ) ;        
SetOption ( "ActivateStopsImmediately", False) ;
SetTradeDelays ( 1, 1, 1, 1 ) ;

BuyPrice =  Close ;
SellPrice =  Open ;
ExitAtStop = 2;
Volatile = True;

SETUP =  C > MA ( C, 200 )  AND   RSI(2)   <  5  AND   C  <  MA ( C, 13 ) ;
BUY     =  Hold ( SETUP, 40 )   AND  C  >  Ref ( HHV ( High, 21 ), -1 ) ;
SELL    =  Cross ( MA ( C, 13 ), C ) ;
ApplyStop ( stopTypeTrailing, stopModePoint,  BuyPrice - Ref ( LLV ( Low, 5 ), ExitAtStop, Volatile ) ;

Please advise on any false.


#2

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:
http://www.amibroker.com/f?applystop

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:


#3

Thank for your quick comment.

It is my mistake of copy-and paste error, the correct one is

 ApplyStop ( stopTypeTrailing, stopModePoint,  BuyPrice - Ref ( LLV ( L, 5), -1 ) , ExitAtStop, Volatile ) ; 

I simplified the code by removing out all parameters, so the cause of my false code.


#4

The question of no delay of Trailing Stop by ApplyStop, with ExitNextBar, Volatile is True and Trade Delay is set to 1, is not clarify yet. Please advise.