Meta

AmiBroker Code for the Breadth Indicator

As per request, I’m including the AmiBroker code for the “30% up/down last quarter in the Russell 3000 index” indicator. I REALLY need to come up with a better name for it than that. How about the Haines Breadth Indicator? No, that’s stupid. Magic Matt’s Mystical Meter? Uh…sure.

It’s a two step process. You must do a scan every day, or as frequently as you want accurate data. It doesn’t hurt if you’re away on vacation and miss a few days, as AmiBroker will fill in the gaps when you return. The scan counts up all the stocks meeting your criteria, and writes these to separate ‘composite’ files that are then read back in by the indicator. You use this with the ‘explore’ process.

…works for all types of data sources. If you don’t get any results, change xx to equal “1” and use AmiBroker’s filter to select current Russell 3000 members.

I run this on a historical set of the Russell 3000 constituents, so it takes a while on my aging laptop. You could also just set AmiBroker’s filter (not the one in the code, but the one used when running an ‘explore’ job) to the current list of Russell 3000 members. Just be aware that your historical data will be subject to survivorship bias. This won’t have any effect on your current readings however…it just means your data will get less reliable as you look back in time.

If you don’t run the composite code regularly, you won’t have any recent data for your indicator to display. It won’t break though, but it won’t be valid either.

Here’s the code for the diffusion indicator. It’s actually generic in the sense that you can compare any two composites (or tickers) you want. It defaults however to the file name used for the “30% quarterly” composite index. It also defaults to a 10 day requirement for a signal to be given.

Thanks for all your work on this indicator. I have setup my AmiBroker with this code and will be watching closely at how it does.

I have typically used the classic 200-day MA as a timing tool, but like this as it seems to warn earlier than that does.

Question, as I believe you have said that your investments are mostly of the long-term variety, do you use this indicator as somewhat binary – i.e. sell all your long-term holdings when breadth goes red and back in when green?

Personally, I find that I need these type of systems to control my emotions and was wondering what your approach it?

Hi Jeremy and thanks for your comment! This indicator is a little conservative, which can be a useful thing. As a practical matter, I use it as a semi-discretionary filter as to whether I will enter long-term trades or not. I still use additional criteria for picking actual stocks, but I will keep from buying new ones when the indicator is red. I use individual trailing stop-losses on stocks, rather than exiting everything when the indicator turns red. And for short-term swing trades, I ignore the indicator completely (because set ups tend not to be dependent on overall market health).

I am a relative newbie with AmiBroker so getting used to things. One thing I want to try to see how I can build this indicator into a backtest that trades in and out of SPY (like you did as you were building this)? Are you able to elaborate on the code you ended up with to backtest this indicator? Personally I would love to see that if you were willing to give it up, as I suspect it is very complicated and beyond my abilities right now!

I don’t use metastock so I don’t have the ability to do that, sorry! I use this indicator as a ‘market health’ indicator when investing in long-term individual stocks. While I tested it on SPY, I don’t actually use it to trade that particular ETF. Thanks for your comment!