ApplyStop issue, always exits at Open price using EoD data?

Hi,

I have been struggling with this for days, read the manual, etc. but nothing I do seems to make any difference so I have finally come to ask here if I am just confused over how ApplyStop actually works?

I am trying to use candle patterns from 'The Strat' as a system in Amibroker, 6.49.1. Specifically entry on a 3-1-2Up or 2Down-1-2Up week in conjunction with a 2Up day where the daily High, daily Close, and the weekly High are very near each other (within a fraction of the ATR (14)). This is working for entries.

I also need a volatile trailing stop at the previous day Low so have been trying to use applystop (% or points) BUT although it exits on the correct day, it always exits at the Open price from that day whereas I would like it to take the Stop Price ideally, or the Low if not, so the outcome is conservative. The settings I change do not seem to make a difference and I have read the manual over and over and searched forums, google, etc. I am still learning so I am assuming I have missed something but can't figure out what it is.

I am using end of day data from Norgate for the US.

I will put below the code aspects that the google searches and the manual have told me are relevant. The total code has all sorts of options in it so really long.

SetTradeDelays(1,0,1,1);
Buy = Open;
Sell = Open;
Short=Cover=0; 

Sell	= 0;

SUp_LastDay_L = TimeFrameGetPrice("L",inDaily,-1);
SUp_Stop = SUp_LastDay_L
SUp_StopPercentage = ((High - SUp_Stop) / High) * 100;

ApplyStop(stopTypeTrailing,stopModePercent,SUp_StopPercentage, ExitAtStop=1, Volatile=TRUE);		// Scenario 1 in func ref.

my settings are:

Example outcome:

Another example:

Results:

i have also tried specifying sellprice but that didn't help either. Can any more knowledgeable people spot what I have obviously missed, or just let me know that taking the open on EoD data is just how applystop works?

Thanks for your time, James

  1. You don't need TimeFrameGetPrice to get previous day Low when using EOD data. Your code should simply be: SUp_LastDay_L = Ref( Low, -1 ); // prev low
  2. ApplyStop would exit at open when gap between previous day prices and open exceed stop trigger level
  3. The calculations you are using cause future leak because High is NOT known for sure until the end of the day and you are calculating stop percentage based on current day low. That is incorrect
  4. Percent trailing stop calculates distance from highest high since trade entry, not from just current bar high, see this KB for details: AmiBroker Knowledge Base » How to plot a trailing stop in the Price chart
  5. You might add few AddColumn calls and run exploration that shows you actual variable values, so you know what values you are really passing to ApplyStop, see How do I debug my formula? like this: AddColumn(SUp_StopPercentage, "PercentagePassedToApplyStop");
  6. If you just want to exit when low drops below previous day low you can do so much easier Sell = Low < Ref( Low, -1 ); SellPrice = Ref( Low, -1 ) ; but again, using Low and High for current bar without delays is a future leak.
  7. You don't need this percent calculation at all, you can use price levels in ApplyStop as explained here: AmiBroker Knowledge Base » Using price levels with ApplyStop function

I have been having a go with it and moved on quite a way. Response 6 was very useful but yesterdays low bit needs to be a trailing stop, so highest fo yesterdays low since the trade began.

Is there where we move back to ApplyStop, or is there still a simple way to do it?

thanks for the help.

Thank you for that detailed replay, exactly what i was hoping for.

Point 1: Understood; however I am getting Open data for the system that includes this/last/previous/3 periods back data for the day, week, month, quarter to understand timeframe continuity so timeframe approach keeps the code consistent to my eye. Does the ref() approach work for higher timeframes than daily without Ref(C, -90) an example?

Point 2: That is the answer I wanted, thank you.

Point 3: What is the best way to specify the percentage/point distance to the stop without using the current High and leaking future day? Is the only way to avoid a fuyture leak here, and for Response 6, to use a sell on Open the next day approach? This system would be using live stops in the market so I really want it to just close the trade if the stop get's touched, and have the amibroker model stay true to that. I will try Response 6 though.

Point 4: Will check this out.

Point 5: didn't knwo about this, will be very helpful. I usually do this manually in excel, but that still doesn't prove what the system is doing so i try to get it to show me on the chart.

Point 7: I tried this but got the same open problem, so switched to the approach here.

Thanks for your time, I will have a look into all of this and come back to you.

James