Automated Trading Machine (ATM) makes it simple to remove fear and greed from your trading. Automated trading is no longer just for the rich or nerdy. Our revolutionary software runs on your computer, using your trading rules, but none of your emotions. There's just one requirement - you know how to use a mouse. Learn more...
PWB#4 - Impossible Entries & Exits
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.
- Printer-friendly version
- Login to post comments
Recent blog posts
- New Release: v3.0.3 - Everything Except Autotrading
- Mid July 2010 Update
- Start of June 2010 Update
- New Release: v3.0.2 - Copy, better error message, more options
- New Release: v3.0.1 - The Stabilise-ening
- Ah, The First Bug [Fixed in v3.0.1]
- New Release: v3.0.0 - The Rewrite
- Start of February 2010 Update
- End Of 2009 Update
- New Release: v2.0.10

Recent comments
20 weeks 5 days ago
35 weeks 6 days ago
41 weeks 4 days ago
41 weeks 4 days ago
48 weeks 1 day ago
49 weeks 3 days ago
1 year 4 weeks ago
1 year 4 weeks ago
1 year 6 weeks ago
1 year 11 weeks ago