A New Swing Trade System Using Bollinger Bands

Of course I’m going to show you the best trade! EMKR on August 7th, 2000, for a gain of 32%.

So I was talking in a previous post about how Bollinger Bands have always intrigued me, and prices seem to very often bounce back and forth between the two bands. Of course this is obvious in hindsight, but there must be some system that could capture many of these trades.

The system I initially developed using ProRealTime showed profitability in backtesting, but with at least one major flaw: the stops were arbitrary, and were way too wide for a “one size fits all” approach. The flaw was there due to the nature of backtesting using ProRealTime…it’s difficult to get a sense of the drawdown and other vital issues. So I came up with another system, which has a vastly improved CAR/MDD (Compounded Annual Return divided by Maximum Drawdown).

But before I go on, a disclaimer: you’re guaranteed to make vast riches with this system!


Disclaimer: assume I don’t know what I’m doing. Do your own backtesting. Do your own forward-testing. This is not financial advice, just a fun little amusement. If one can call little snippets of computer code an amusement.

Anyhoo, you’ll notice this system has some things in common with the first attempt. Four bars in a row that have lows piercing the lower Bollinger band, followed by one that doesn’t. You buy at the open of the following day. You sell when it hits the upper Bollinger band, and then stops piercing it with the highs. Here are the details, the parameters of which have been thoroughly tested using AmiBroker.

• Go look at the S&P 500 index (or the SPY etf equivalent). Get a chart that shows moving averages with periods of 40 and 120 days. The 40-day curve should be above the 120-day curve. If it’s not, the market is sucky and you should be finding other things to do for awhile.

• This is a five-bar sequence. Your stock should have four consecutive days with lows that are lower than the low Bollinger band. Set your “B Bands” up with a period of 15 days, and 2 standard deviations (2 is usually the default). Note these don’t have to be “down days”, where the close is lower than the open. You’re just looking at the lows and the lower band for this part. In the example above, the last two bars are actually up days…just doesn’t matter.

• The most recent “piercing low” must be lower than the earliest one, otherwise it’s a vague and hazy sort of decline that likely won’t bounce back.

• The fifth “trigger” day in the sequence is a a bar with a low that does NOT pierce its B Band. For this trigger bar, it must be an up day (Close>Open) and volume for that day must be greater than the average volume of the past 20 days. So you’re going to need a moving average for your volume as well.

I did test to see if the system worked better with the trigger bar being a big percentage, or if volume needed to be very much higher than the average, but the best results were as stated above.

• BUY at the open following the trigger day. *

Then what? Wait for your riches to roll in! Wait patiently until the price moves upward.

• When the highs start piercing the upper Bollinger Band, you need to start paying close attention. Each day it pierces…yay! You’re potentially making more money. Look for the first day of this sequence of piercings that does NOT pierce the B Band. Sort of the inverse of the entry day. That’s your neon sign saying it’s time to get out.

• Sell at the open of the following day.

• Also set a stop loss! My stop losses are usually “soft”, i.e. I don’t set them with the broker. Instead I check the close of each day, and if it’s fallen below my stop point, I sell on the following open. This avoids any close calls where the low fell temporarily below the stop, but then recovered. Also it’s just easier so I don’t sit there watching the “tape” all day. Your stop loss should be 14% (i.e. multiply your entry price by .86 and there’s your get-out-of-town price). Yes I tested a range of stops between 30% and 3%, and 14% worked best.

Some other details:

• Only choose stocks that closed higher than $15, with a average volume greater than 100k shares. Smaller than that and you might buy an erratic, frisky stock that misbehaves like a drunken groom at a bachelor party.

• If you’ve got too many stocks to choose from on a particular day, set up an Average True Range indicator with a period of 10. Divide each stock’s ATR by the Close of the trigger day (ATR/Close, which will be a tiny decimal number), and pick the one with the highest number. This will give you the stock that is the most volatile, and thus the one that has the potential to give you more profit.

• Oh and do bother to check the stock out on various sites such as seekingalpha.com, finviz.com etc. Make sure that there isn’t any dreadful recent news or financial info that is going to ruin your day. With short-term plays like this, the fundamentals aren’t as important as for long term trades. But you still don’t want to buy a real dog…or at least you want to proceed with your eyes wide open.

And that’s it! Let me know if you have luck with it. If anyone wants the AmiBroker or ProRealTime code for this, just drop me a message here.

* UPDATE 02/15/15. After reading Jay Kaeppel’s book Seasonal Stock Market Trends, I took a look at some of my swing systems to see if they could be improved by only trading during certain times of the year. Sure enough, this swing system improves if you do NOT trade during the month of May. And it improves even more if you exit any trade that happens to overlap into the month of May. Why? No idea. Doesn’t matter, just avoid May for improved results.




Setting Stop Losses and Falling Markets

Your investments should never end up in freefall!
Your investments should never end up in freefall!

The average investor – and I mean the kind who wouldn’t bother to read this blog – never thinks about an exit strategy. He or she buys a stock because it looks promising, with plans to hold it until retirement or some other life event requires a large chunk of money. This “buy and hold” strategy is perfectly reasonable, except for the times that stock prices go down. Which happens a lot!

In fact, the average investor is more likely to sell too early, and miss out on profit. But sell too late, hoping the stock price goes back up. This is a bad, bad, BAD idea. An example:

Let’s say you finally succumbed to all the talk about people getting rich off the stock market, and in May 2007 you bought an S&P 500 index fund (an “ETF” fund designed to mimic the movements of the S&P 500 index) at around $151. By October, the crap hits the fan and the market starts a long, painful plummet to depths never before seen. All the while, you hope and pray it’ll turn around sometime. But this plummet is a deep one. Did I mention a painful one? It’s “the Great Recession”. At the depth of the plunge in March 2009, the SPY was valued around $69 per share. That’s a loss of 54%! The market did eventually go back up of course, but it wasn’t until January 2013 that the price of the SPY fund equaled your hypothetical investment of $151.

So what, hey at least it went back up, right? NO! That’s almost six years where your money was worse than useless. Your cash just sat around, not working, drinking beer and staying out late at night, contributing nothing toward your retirement. That six years might make the difference between which golf club you join in your retirement.

The horizontal line indicates your hypothetical $151 investment.
The horizontal line indicates your hypothetical $151 investment.

Imagine if, back in that fateful May of 2007, you said to yourself “Self, here’s what we’re going to do. The market’s still going to go up. Way up! To heights never before seen or imagined. I can feel it in my soul. But…just in case…if it ever falls from its peak, we’ll sell. Maybe 10% down. What do you think? Self? Now don’t cry, it won’t ever happen, it’s just an emergency ‘stop loss’ in case the unthinkable happens…”

The market peaked soon after your investment at around $155, and then fell and fell. But you summoned up the courage, and in January when it fell to below 10% of that, you sold.

Ok so you lost about $11 per share. And then you just sat and waited.

Then, shortly after the market hit bottom, it was back up by 10%. You had a little internal conversation again, and decided to get back into the market. Your 11$/share loss was soon erased and then some! So when January 2013 rolls around, you’ve made a gain of $81/per share. Sure you lost 7% on your initial investment. But you then just about doubled your investment on the way back up. 100% profit! You would have just been breaking even if you hadn’t gotten out of the market.

And keep in mind this was a fund that spreads the risk over many stocks. You might have gotten lucky and found a stock that didn’t fall quite as much. Or you might have picked a stock that simply went out of business, turning your investment into only a good story to tell your grandkids.

EVERY investor should have an exit strategy for when things don’t go as planned. My wife once said to me “you don’t believe in company X, so that’s why you want to sell.” I replied “no I do believe in that company and I think they’ll do great in the long term! But their stock is way down from the highs and I want the opportunity to make money on them twice!”

Since these are shares she bought, we are still negotiating this little issue….

Next post: how to actually set those stops, at least from this one guy’s perspective.


Where Are the Customers’ Yachts?


While many books about trading and the stock market quickly become irrelevant, certain aspects of the markets are timeless. I’ve been going through my local library’s bookshelves, looking for books that might provide some insight. Most are technical in nature, but I’m currently reading Where Are the Customers’ Yachts? (or A Good Hard Look a Wall Street) by Fred Schwed Jr.

It was originally published in 1940, and has been reprinted several times since then. It’s a light-hearted, satirical and amusing roast of Wall Street and the players involved. Brokers, retail investors, bankers, chartists, short-sellers…no one avoids scrutiny. Given the book’s age, it’s amazing how much of it is still deadly accurate today. So if you want a short read and a good chuckle, I recommend it.

A link to the book for your convenience (no affiliation).

Swing Trading System using Bollinger Bands

The black arrow is the signal day, and the green arrow is the trade day (at open).


As promised, here is the system I was using that initially got me into the EXAM (ExamWorks) trade, making me over 10% in about 30 trading days, after commissions. But before I go any further…


Why? Because the stop loss and profit target values are highly suspect. In fact, I modified these after I initially made the trade, because they were unreasonable. I’ll explain that a little further down.

I’ve always been fascinated with Bollinger Bands. It’s amazing how the price bars just flow between them, bouncing back and forth and never quite escaping. This of course is all backwards, because the bands are there BECAUSE of the price bars, not the other way around. Cause and effect is an important thing to keep straight when trading stocks.

That said, there are some recurring patterns that intrigue me. I’ve noticed that after the lows have hugged the lower Bollinger Band for awhile, they usually head in the other direction. Then, if all goes well, they smack up against the high Bollinger Band for awhile, like helium balloons on the ceiling at New Years Eve. Rinse, and repeat.

The system I came up with that got me into the EXAM trade was this:

• All trades occur at the open of the following day after the signal. This allows me to actually work for a living and then make my trading decisions after the market is closed, and put my orders in overnight for the opening bell.

• Market must be in an uptrend, as determined by the S&P 500 (SPY) having its 65-day moving average be above its 195-day moving average. No point in trying this in a bear market. *

• Close price must be above $15 and average 10-day volume must be above 100,000.

• I used a Bollinger Band of 20 periods and 2 standard deviations, based on the closing price. (I’ve since changed that…)

• My screening software looks for four bars that have their lows below the lower Bollinger Band, followed by a fifth (most recent) bar with a low above the Bollinger Band. The last low below the Bollinger Band must be less than the first low below the Bollinger Band. Just to be clear, if the signal day is day 5, then day 4’s low must be below day 1’s low. This little plummet can have other bars before it with lows below the band, but it’s the four below and then one above scenario that we’re looking for. Check the lead graphic as an example. NOTE: I’ve since tested and found that four bars below works better. But I didn’t use that for this trade, so you’ll only see three bars.

• Buy at the open of the day that follows the signal day (the bar with the low above the band).

• Now here’s where it gets particularly dicey. Set a stop loss at 15% and a take-profit amount at 21% above what you paid for it (the “tradeprice”). In other words, if the price closes either below .85*tradeprice or above 1.21*tradeprice, then sell that puppy the following day at open.

When I did all my backtesting with ProRealTime, I could only test a single stock at a time. So I would enter all the data into a spreadsheet and add up the totals. I would compare various variations to each other, and pick the one that made the most money. From a sheer time/fatigue standpoint, I could really only do this for 30-40 stocks at a time. PRT doesn’t allow you to test on a portfolio-wide basis over a whole universe of stocks.

So the reason this is dicey is not because it won’t make money…it tested pretty well in that regard. The problem is the drawdown! The other problem is the amount of time your stock might just be sitting around, drifting one way or the other, taking forever to hit either the stop or the profit target.

I picked 15% as a stop loss because I’d read somewhere that 15% was a good number. I’ve also heard lots of other numbers since then. The problem with a fixed percentage either as a stop loss or a profit target is that some stocks aren’t volatile enough to get to either point very quickly. Which really misses the point of a swing trade.

I’ve since run this scenario through AmiBroker, which allows me to test across a big batch of thousands of stocks. When I tested with data from 1/1/2000 to 12/27/2014, I got a profit gain of 169.41%, bringing a hypothetical investment of $30,000 to $80,821.94. That was reasonably decent compared to some other systems I’ve worked up. The problem, as mentioned before, is the drawdown.

1. Portfolio Equity

Look at those big dips as the market fell apart in 2002 and 2007-2008. Interestingly, this system is kind of flat in 2014, even though the market has been on a upward tear. The sign of things to come?

Note also the straight lines at the end of 2002 and between 2008-2009. This is where the filter for the S&P 500 kicked in, keeping me from trading in a bear market. Otherwise losses would have been much larger.

2. Underwater EquityThis hypothetical portfolio traded a maximum of 5 positions at a time. Look at those painful drawdowns in 2003 and 2008…a maximum 24% of the entire portfolio! Hurts my eyes to look at.

So how to fix this? One way would be to use stop loss and profit targets that are tailored to the innate volatility of a particular stock. One way is to use Average True Range as a basis for stops and targets. This tailors the exits to what the stock has the potential for, rather than some one-size-fits-all percentage. I’ll talk about that in a future post.

By the way, most of the portfolio-related stuff I’ve learned from Llewelyn James, either through his book or directly from him. Including the reasons for why 15% is a dumb number to blindly pick. This particular swing system (DON’T USE IT!) is all my creation though.

Disclaimer: I think I mentioned enough times that you shouldn’t use this system. Not just because trading in general is risky, but because this system isn’t particularly good. If you’re into CAR/MDD** ratios, it has an embarrassingly low value of 0.17 It is however the basis for other ideas that appear to work better. Oh and I should mention that once I realized a 15/21% stop/profit was f-ing cray-cray, I changed it to a 3 x ATR/4 x ATR stop/profit instead…which got me 10% profit.

Now I’m going to go sit and watch my leveraged short-oil ETF as it goes through the roof. 🙂 Oil dipped below $50 today, and I’m cheering for it to go lower.


* BTW I’ve since started using a 40-day vs 120-day comparison for bear markets…a little faster to respond to a downturn, but also will likely create a little more choppiness and false starts at the end of a downturn.

** Compounded annual return divided by the maximum drawdown. This rewards profit but also penalizes drawdown. Keeps your account from hemorrhaging money while you’re waiting for the next big win.

Backtesting with AmiBroker vs ProRealTime


So I finally bit the bullet and bought AmiBroker, which is comprehensive stand-alone software for charting and – more importantly for me -backtesting technical buy/sell systems.

Up until now I’ve been using ProRealTime.com‘s free Java-based charting software. The end-of-day data version is free, but their realtime intraday version is subscription based. It’s really nice considering the price, and allows you to program stock screeners and do limited backtesting using a BASIC-like scripting language. Other than being a little buggy sometimes, it’s a pleasure to use.

The major drawback to it is that you can’t backtest your trading systems across an entire universe of ticker symbols. You can only do one ticker at a time. So to get a decent overview of your system, you have to individually test each stock, record the results in a spreadsheet, and then add or average things up to get a sense of how one system might compare to another. But even testing 30-40 stocks can be quite laborious, especially if you’re also tweaking parameters in your system.

Enter AmiBroker. While there are web/cloud-based backtesting platforms available, those are mostly subscription-based. AmiBroker is the only software I know of that is standalone, will test a large batch of stocks at once, and costs a one-time fee. It’s not cheap ($279 at this writing) but I finally decided it was worth the ‘investment’.

I’m a Mac guy, so the fact that it’s PC-only is a drag. I had contemplated running it on a Windows virtual machine on my Mac, but fortunately my kids got a new Windows laptop for Christmas, and I’ve inherited their old one. So I’ve installed AmiBroker and am slowly getting the hang of it. It’s complicated, but having already learned ProRealTime, I’ve got a head start. Note the two platforms are unrelated except that they’re both charting software.

Tonight I was able to translate one of my systems from ProRealTime into AmiBroker’s scripting language, and for the first time ever was able to run a test over a large group of stocks (thousands) and over an extended period of time (Jan 1 2000 to the present). I picked my most winning-est system to test. And the results?

Kinda pathetic.

Why does the system look so good when picking supposedly random stocks on ProRealTime, but look so bad when using AmiBroker? No friggin’ idea. A little depressing, but I guess there’s room for improvement before I invest more money with that particular system.

P.S. The way the two platforms are configured, I will probably continue to use both of them. I’ll use PRT for checking my latest trade data and possibly screening, and AmiBroker for the actual backtesting. We’ll see if that changes going forward.

UPDATE 01/07/15: One thing I’ve found is that the free downloadable EOD data from yahoo finance has a few errors in it. Every once in awhile I lose my shirt or become an instant paper-millionaire due to glitches in the data. I’ve gotten into the habit of a) checking the best and worst trades of a backtest to make sure they don’t look suspicious, and b) not refreshing my data very often.

Wait, what? Not refresh the data?! Yes, really. If I’m testing 15 years of data, does it matter if my end date is 12/27/14 vs 01/07/15? No I don’t think so. And I’m not currently using AmiBroker as screener, so fresh data is not worth the hassle of cleaning it.

Also, AmiBroker allows your backtests to look into the future, which is a bad thing. And it’s quite easy to do it in a subtle way too, like for example accidentally using the Close price as a signal while buying on the Open price of the same day. So it’s important after designing a backtest system that you check to make sure the buy and sell prices are exactly what you expected them to be, and occur on the days your system indicates precisely. While there is a function to test for crystal-ball-reading, it’s not automatic.