I'm using ATR-based trailing stops (ExitAtTrailingStop) in my code (below), but the strategy doesn't close the position at the trailing stop levels i specify - it executes it a lot later and i incur a higher loss than expected.
-> I checked the p.TrailingStop property in my PrintDebug and it's correct. Why is it not closing the position at the p.TraliingStop level?
CODE:
Please log in to see this code.
Size:
Color:
I'm certain that it's exiting exactly at the level specified (it must). The problem (I'm guessing) is that the exit logic is processed only on the bar on which there is a TurnUp or TurnDown. This is likely to occur much less frequently than you expect. If the idea is to process the TrailingStop on every bar following a TurnUp/Down, then you need to program it that way. Again, I'm just guessing based on what you've coded.
Tip: Call PlotStops(); to plot a small dot at the stop level on the bar on which a stop is activated. Call it just once, above the loop.
Size:
Color: