Comparative Relative Strength

I’ve been reading some of John Person’s books lately.  If you haven’t read anything by him, you owe it to yourself to get a hold of his trading books and read them.  Seriously, they are some of the best material that I’ve read on trading.

I recently picked up Mastering the Stock Market again in preparation for my interview with John, and one chapter in particular caught my eye–the chapter on Comparative Relative Strength.  (Note that this shouldn’t be confused with the “RSI” indicator, which is the “relative strength indicator”.  The two are completely different.)

The basics of Comparative Relative Strength (CRS) is that you take one chart and divide it by another. The result is a simple line graph of the relative strength of the two markets.  The line graph is the “difference” between the two charts.

For example, you might take the chart for JP Morgan (JPM) and do a relative strength comparison to the XLF financial sector ETF.  What this does is it tells you how those two markets compare to each other.  This is specifically interesting when you compare a stock and a sector ETF, because it tells you how well the stock is doing compared to the rest of the stocks in its sector.  This is one way to do sector analysis.

Another way to use this would be to compare an individual stock with the S&P 500, which will tell you how the stock is doing compared with the broader market.

So, if the stock and the market we are comparing it to were exactly aligned, the result would be a straight line.  Not interesting.  However, when we compare JPM and the XLF, we see places where the stock is outperforming the rest of the financial market where the CRS line is trending up.  That’s good to know, especially when evaluating a stock. You not only want to know how it’s doing individually, but especially how it’s doing compared to its sector.

I set up this exact pair on both the ThinkOrSwim platform and the Amibroker platform, and it works beautifully on both platforms.  With ThinkOrSwim, the indicator is called RelativeStrength, and you set up the one stock in a chart, and set up the Relative Strength chart in a lower sub-graph.  In Amibroker, it’s a function called RelStrength.  It appears to be common enough that it is likely to be in other major platforms as well.relative-strength

Here’s the best part of the chapter: you can apply a moving average to the Relative Strength line and use that as a buy or sell signal.  The same way you might have used a moving average on just a stock in the past, you can now use a moving average on the relative strength of a stock within its sector.  Because moving averages act like automated trend lines, you can program a system with a moving average to alert you of changes in the trend.  That means when a stock begins to outperform its sector, you can be alerted of this fact (and buy); when the stock performs poorly compared to its sector, you can be alerted that the trend is over.  John describes how you can use this CRS with a moving average system to write a tool to automate the signals.  Though not a full trading system, it would be used to alert you of stocks that are outperforming the rest of the market, as well as stocks that are under-performing.   The automated alert system would scan for the change in relationship to let you know when a stock was trending higher than the market or ending that trend.

If I were to pick one project to work on next, this would be it.   Sector analysis is powerful, and it should definitely be part of your tool box.

My Favorite Forex Book

One of the first books I read on Forex trading was John Person’s Forex Conquered.  I was just re-reading parts of that book this week, and I wanted to highlight some of the best parts of the book.

John Person has a whole section on Trading Systems in which he explains how some of his tools and strategies from earlier in the book can be applied to automated trading systems.  Person’s strategies are excellent for automated systems because they are clear-cut; he has discrete rules for entries and exits, as well as for profit targets and stop losses.  In fact, the almost every chapter of “Forex Conquered” has knowledge that can improve your automated trading systems.

Person has a couple trademark tools he describes in almost all of his books: Pivot Points, seasonality, and the Doji chart pattern.  The Trading Systems chapter covers Pivot Points, and touches on seasonality with respect to automated systems.

Person takes three separate automated trading systems and compares their results.  He first explains a system that uses Pivot Points and the Stochastics Oscillator; he describes the system’s sell logic in that it waits for price movement through Pivot Point R1, R2 or R3, and then looks for the Stochastics Oscillator to cross up over the 80 percent level, and then back down over 70 percent level.  (Buy signals are similarly calculated.)  He also explains some of his thought process on setting stops, and reasonable profit targets.  And best of all, he provides some actual code to look at.  In this example, he shows the system written in TradeStation’s EasyLanguage programming language.

At the end of this section of the chapter, Person presents some statistics showing net profit, profit factor, winning percentage, and the standard stats you would expect to see from a trading system.  Just for a point of reference, the Profit Factor of this system is 1.86.

The second system that Person explains is one that uses Pivot Points and the MACD histogram indicator; the program logic is essentially the same as the Stochastics program, with just the indicator switched to the MACD.   Again, Person presents the statistics for the MACD version, and compares the results with the Stochastics version.  The Profit Factor for this MACD system is 1.35.

He concludes that the Stochastics version is a bit better, because the MACD’s signals lag a bit behind the price movement, and thus we are not able to enter a trend at the beginning or exit at just the right time.

The third system Person looks at is his Moving Average Pivot Point system (which he calls Defcon III). This is his trademark system, and it has served him very well over the years.  When Person teaches trading to new traders, the Moving Average Pivot Point system is usually a part of it.

John Person describes much of how the moving average automated system works, and gives nice hints as to how it should be programmed.  However, he does not provide code for this system, and in a conversation with him last year, he mentioned that was intentional.  It’s left as an exercise for the reader.

I spent some time writing this system for Metatrader 4, and it is working quite well.  It’s not perfect yet, and I need some more time on it, but I like the results I see.

At the end of this chapter, Person shows the statistics for the Moving Average Pivot Point system, and as you might expect, the stats are much better for this system, compared with the other two.  The profit factor for this system is a nice 2.03.

Even though the book has been out for a while, if you haven’t read “Forex Conquered”, I recommend that you do.  The Pivot Point Moving Average system is explained in a number of chapters throughout the book, and I believe the concepts should be part of every trader’s toolbox.

Seasonality trading system

Here’s more about Howard Bandy’s book Quantitative Trading Systems by Howard Bandy.

This stuff is amazing.  I’m reading the section on Seasonality Systems, and Bandy has a trading system that just buys an asset (stock, currency, etc), the same trading day each month, holds it for two days, and then sells it.  And it makes money.  Holy Cow!  The program lets you find the best trading day for various stocks, and I back-tested a number of stocks, as well as the EUR/USD forex, and a good number of them make a profit, including the Euro.

How can this be?  Can this really that simple?  I’m doing more testing on this idea, and if it really works, I’ll put this into a real trading system, and put it out there on a demo account.  Stay tuned.

Seriously, I’m spending hours studying trading systems and complex algorithms, and they do just as well as buying a stock and selling it 2 days later?  We’ll see.  This needs further investigation.


Howard Bandy rocks

I just purchased two books by Howard Bandy: Quantitative Trading Systems and Mean Reversion Trading Systems. These are seriously must buy trading system development books. Buy them. There’s another one I haven’t bought, and it’s on top of my buy list: Modeling Trading System Performance.

I recently wrote about another trading system book which gives a great overview of trading system development. But Bandy’s books gives all kinds of examples, source code, formulas, and deep deep technical explanation — the kind of stuff I just live on!

Seriously, if you are developing trading systems of any kind, these books are required reading. The Quantitative Trading Systems book starts with general concepts of development, and goes through entries and exits, indicators, four different kinds of systems, portfolio management, and how to determine if your trading system is still working.

One small thing I learned is that when you are developing a trading system, the first thing you need to do is choose your metric. What makes you happy? What really matters to you in a trading system? If you’re like me, the first thing that comes to mind is net profit, right? You want the system to make money. Ok, fine, but if it loses 12 trades in a row, and draws down half of your account before it turns around and makes a couple good trades, is that ok? Probably not. Those losses are painful. So, maybe your top metric would be minimal drawdown, or even better: the Return to Draw Down ratio. So, if you have a good return to drawdown ratio, but it only makes one trade per month, how about that? Would that make you happy? No? Not so much. I want to see more trades. I want to make sure it’s doing something. Bandy goes through a list of different metrics that might be important to you as a systems trader, and he stresses that it is important to pick the kind of metrics that are important to you.

I’m about one third of the way through the book, and I’ll have a proper book review when I’m done; but I had to get this out there today to tell you how amazing this stuff is. Buy the book. You can’t lose, it will improve your development skills!

Trading Systems Book Review

Trading Systems by Urban Jaekle and Emilio Tomasini

Trading Systems has changed my life. That’s a stretch, but it’s true. I have been working on writing automated trading systems for a some time now, and this book has given me direction and focus to that task. Previous systems that I have written were done by finding all the details and rules of a manual trading system, and coding each one into the automated system, trying to figure out which rule might take precedence, and whether one rule of the trading system might be more important than another. I’ve come up with what I thought were moderately profitable trading systems, only to see them under-perform in the real world. Enter Trading Systems, which clearly showed me I was doing things backwards, and that there were much better and more reliable ways to test a system’s viability.

The most important thing I learned from this book is that the trading system itself can be be very simple; actually, it must be very simple. The example the authors use throughout the book is the LUXOR system, which is the simplest of moving-average cross-over systems, probably the first trading system anyone learns. Tomasini shows that the system tested against historical data does well; it is profitable with very simple trading rules. Even better, the LUXOR system is free; he tells you where you can download it. The code is presented in EasyLanguage, but it is simple enough that you can translate it into Metatrader or Ninjascript, or whatever your language of choice.

The next important thing I learned is that once you have run some tests to show that the system is basically profitable, there is a correct order of what to do next. In my own previous work, I threw in indicators, trading rules, stops and profit targets, Money Management rules, and everything all at once; but Tomasini is clear that the very first thing you should do is get the trading algorithm to work well on its own. Then, add a filter to two to weed out some bad trades; in the book he adds a time-of-day filter to limit when the system can trade.

Only then do you start thinking about stops, trailing stops and profit targets. In the world of discretionary trading, that’s crazy talk. In my manual trading, I have always been taught that you determine your stop at the same time you determine where you will place the trade. That idea gets drilled into us at every trading class and lecture — Use stops! But in automated trading, the algorithm must be profitable even without stops. In fact, after adding stops to the program, the total profit doesn’t change very much. What does change is the drawdown; using stops, especially trailing stops, drastically reduces drawdown on the account.

The last thing that gets added into the system is money management (or the trademarked term “Position Sizing”); once a good money management system is coded in, the system goes from profitable to uber-profitable. A simple money management rule is that the system will always trade only 2% of the account’s equity. As the equity increases, so does each trade size.

Tomasini spends the majority of this first section of the book on back testing and optimization; dozens of interesting graphs show the testing results after each change is made to the code. His graphing software is making me a bit jealous, and I’ve got it on my list to figure out how he does those graphs so that I can do my own.

One thing that is interesting about optimization is that you have to be clear about what you are optimizing: profits, or percentage of profitable trades, or the average trade, or minimizing drawdown. These various goals need to be clear your mind before you begin optimizing. It’s not enough to say that you want the system to make as much money as quick as possible. If you optimize only for net profit, and ignore drawdown numbers, your system may well wipe you out before you get to profit.

The important lesson of back testing is that over-optimization will make a trading system look good with historical data but perform poorly in the real world. Tomasini spends a lot of time explaining how to not over-optimize. One of those methods is to use walk-forward analysis. What that means is that you use a portion of your historical data to optimize your algorithm’s parameters, and then another portion of the data to test those parameters. In other words, you use half of your data for training the system, and the other half (the “unseen” half) for testing. This is known as “in sample” data and “out of sample data”. These are really important concepts, and make all the difference in the world on creating a profitable system. Walk-forward analysis keeps moving the window of in-sample and out-of sample data forward through time, and each time you get parameter results that are little better than before; by “better”, I mean more robust, and more likely to work well long-term.

Two more concepts Tomasini describes for testing the robustness of a system are timescale changes and Monte Carlo analysis. Timescale changes just means that if you have tested and optimized your system using 1-hour chart data, then you run the tests against 30 minute or 4-hour chart data, and see how it performs. If your system still does moderately well, you likely have a good system.

Monte Carlo analysis sounds so cool that I just like saying the words: “Monte Carlo Analysis”. Monte Carlo Analysis is a tool that checks for the worst case drawdown scenarios. The analysis re-organizes the order of your trades randomly, and shows you various scenarios. Your beginning equity and ending equity are still the same, but the order in which the trades are taken is randomized a number of times. Some of the equity curves will be better, and some will be worse. The analysis shows the worst case scenario on the drawdown on your account for the trading system you are testing.

Finally, Tomasini recommends periodically re-optimizing your system. Markets change over time, so if you re-optimize and re-analyze your system periodically, you can keep it generating good profits.

This is probably one of the best books I have read on my particular niche of trading systems; if you have any thoughts of developing a profitable automated trading system, you need to ready and apply Trading Systems.

(Note: The second part of the book is on portfolio optimization, which is a topic I will cover in a later entry.)

Trading Systems: A New Approach to System Development and Portfolio Optimisation