Monday, September 5, 2011

How to Set Stop Orders in the Stock Market: A Quantitative Analysis, Part I

Introduction

     Trading as War

To throw or not to throw...
Stock trading is often compared to war. Your dollars are your soldiers and your various order types are your weapons. If the buy limit order is your basic M-16 rifle, then the stop order is surely the hand grenade. Used improperly stop orders can be at least as deadly to you as to the enemy. And far too many people end up throwing the pin while holding onto the grenade, with the predicatble unfortunate results.

     Stop order considered harmful? 

For that reason, there's a whole school of thought that argues against using stop orders entirely. However, I don't want to get into that debate today. If you've already decided that you want to use a stop order, just where exactly do you place your order so that it will protect you and not blow up in your face?

Place the order too close to the market and you are likely to get stopped out on noise, only to witness your stock then  take off without you on board. Placing the order lower reduces the effects of noise but increases the damage to your account should your grenade go off. They say "Your first loss is your best loss". But they also say "Beware the death by a thousand cuts", meaning that a lot of small losses can kill you just as dead as one big loss. How to reconcile these two conflicting aphorisms?

There's a nice article on the subject over on streetauthorithy.com called Setting Stop Loss Orders which gives a good overview of the problem but it doesn't really give you a good method for choosing stops. In fact, there's a lot on the web about different techniques for setting stops using technical analysis or price calculations, but I've not found any objective analysis of just how well stops work and if they actually do more harm than good.

I should add that here we are concerned only with stops that are placed on opening a trade to limit potential losses, not trailing stops the follow an already profitable trade in an uptrend.

The Experiment

     Method

I decided to conduct an experiment using one week's worth of one minute OHLC data from the ES e-mini futures, 8,367 bars between 3 PM August 25th, 2011 and the close on September 2nd. The experiment is simple. We will place orders to buy ES using the BASH algorithm (Buy Anywhere, Sell Higher) at every bar in the data set. If the price then moves higher, the order is considered a winner and we move on to the next bar and place a new trade.

For the purpose of this experiment, we are not interested in when to close out a winner, just what to do when the action goes against you. If the next bar after entering a trade is lower, we set a series of stops at quarter point intervals. The trade then continues until one of two things happens: either the price reverses before the stop is hit and continues higher back above the purchase price and the trade is then considered a winner, or the stop is hit and the trade becomes a loser. We then total up the number and size of losers at every stop level.

ES one minute closing prices, 8/25/11 - 9/2/11
The question we want answered is simple: What stop level produces the smallest total losses over the entire week of data? First, let's look at the raw data.  It looks pretty much like any graph of stock data.  To quote our fearless President and stock guru, B. Obama, "the market goes up, the market goes down".

Each trade was entered on the open of each one minute bar.  Decisions of whether or not to take a stop loss were made on the closing value of subsequent bars.  Any losing trade that was still running by the end of the data set (which is when trading stopped at the end of last week) was considered to be a loss.

Obviously we want to buy the dips but when you're on the right edge of the chart, it's not so easy.  So our experiment will buy every single candle and see where the resulting 8,367 trades sort out at quarter point stop increments from 0.25 to 25 points.  The entire program is coded in Matlab.

     Results

No. of losing trades vs. total loss at different stop levels
Here are the results.  The blue line shows the number of trades that got stopped out at each stop level.  The stops were tested in quarter point increments, the smallest increment that can be used when trading ES.  The green line shows the total amount of the loss at each stop level in points.  I don't know about you, but I found the results to be just a bit surprising.

The primary result is that the wider your stop, the less often your stop gets hit.  That may seem like something you already knew, but it is not necessarily completely obvious.  It is also interesting to observe that this effect does not decay linearly, but rather parabolically.

The curve flatted out after 11 points.  Setting a stop greater than that did not cause you to have fewer losses, but did continue to increase your total loss.

But perhaps the most interesting result is that the total loss curve is monotonic increasing.  The implications of this are discussed below.

     Discussion

I must admit that I was somewhat surprised by these results.  I had always assumed that setting a very narrow stop wasn't a good idea, but apparently the old advice, "Your first loss is your best loss" is exactly right.  It turns out that you will lose the smallest total amount in a day trading type ES trade by setting your stop at 0.25 points, the smallest stop possible. You will have lots of losses, but they will all be small.  And the key point is that taking fewer losses by using a wider stop does not reduce your overall loss, it increases it.  Thus the idea of the "death by a thousand cuts" is disproven.

However, since the smallest stop is apparently the best, the issue of commissions, which I ignored for this experiment, becomes important.  I really hadn't expected that.  My broker charges $2 per ES contract, or $4 per round trip.  With a 1/4 point stop, more than half your trades will be losers.  That means you need the remaining ones to do more than double that to break even.  A 1/4 point gross gain is $12.50, less $4 commisions = only $8.50 profit.  But a 1/4 point loss is -$12.50 less $4 commission = a $16.50 net loss.  Therefore, your winners have to be at least half a point.

The other important issue is the spread.  During the day, ES provides enough liquidity that the spead is usually just 1/4 point.  However, there is no way to tell from OHLC data whether the prices reflect trades that occurred at the bid or at the ask.  With tight stops, that makes a difference.  And if you can't buy on the bid and sell on the ask, you need to add another quarter point to ensure a winning trade.  Setting a quarter point stop may prevent that from happening.  Taking the smallest possible loss doesn't do you much good if that also prevents you from making a profit.

     Future work

This wasn't supposed to be a master's thesis, so I'm going to wrap it up here and come back to it in Part 2 later on.  The remaining questions that need to be addressed are:

1. How do commissions affect the results?

2. How does considering the spread change things?  I think to answer this, I will program the BASH algorithm for my trading program and see how it does on live data trading ES.  While still not as good as real trading, paper trading is at least better than using static historical data.  And my broker's paper trading system works pretty well.  (I don't really have the nerve to try this for real).

3.  Why does the stop loss curve not decay linearly and what implications does this have on choosing stop levels?

4. And of course the big question: where is the ideal stop level, really?  With commissions and spreads, it's probably not a quarter point.  But it's definitely not 10 points.  The answer then lies somewhere in between.

I also want to look at other types of data, like SPY or individual stocks.  In the meantime, I think there's certainly some food for thought with the results so far.

3 comments:

  1. Interesting on stop losses. Thanks for sharing your work.

    ReplyDelete
  2. Thanks for reading I should have some more results by the end of the week.

    ReplyDelete
  3. Very good analysis. Thank you,

    ReplyDelete

Due to some people who just won't honor my request not to post spam on my blog, I have had to re-enable comment moderation. Comments may take up to 24 hour to appear, depending on when they're made. Sorry about that.