I hope everybody knows what a "gap" is.
Well, sometimes your backtesting routine will determine that it needs to set a long entry order at a particular price. And probably your backtesting routine will say "ok, our intended entry price is at this level, did the price go above that point? If so then we're in the trade". Or something like that.
And your backtesting routine will record that it entered long at that price:
21-Nov-2005 18:00:00, Entered long trade at 1.2995.
Problem is though, that just because the price went higher than your intended entry price, it doesn't necessarily mean that you were able to open the trade at that price. Because of gaps.
You can't just assume that you were filled at 1.2995 - you have to check if the open price of the bar was below your intended entry first. If it was, then you can say you entered at 1.2995. If it wasn't, that's where your last gasp entry price comes in - was the open below that? If it was, then you can say you got in at the open price. If the open was above the last gasp, you didn't enter the trade.
What if the price was higher than your last gasp, and then came lower after the open? Did we enter the trade or not? Well, I tend to think that if the open is higher than the last gasp, then we cancel the order. We don't know what's going to happen in the future. And if you enter long while the price is going down, that seems to me to be the wrong thing to do.
The same rule applies for exits, although we don't have a "last gasp" here. The rules say we want to move our stop loss to 1.2995, for a break-even setting. The next bar opens above that price, and drops through it, then we can say we exited at 1.2995. But an open below our stop loss means unfortunately we just have to get out at whatever the open price was. There's no waiting for it to come back. That's praying. Maybe it will and maybe it won't. Stop losses are about risk management, and must be followed.
That's why in a system where you set the stop loss to be exactly 50 pips below the entry, you might still end up with a loss of 55 pips or something.
So that's gaps covered. There's also this thing called slippage. You might like to include a standard slippage of a number of pips just to be on the safe side. You want your backtesting results to be more negative rather than more positive. Slippage is where you want to get in at 1.2995, but your broker fills you at a higher price. Common with stocks and options. Less so with currency, but still possible.
Essentially, whatever your profit/loss was, just deduct the slippage from that and calculate a new profit/loss.