The Trend IS NOT Your Friend

trendiness-explainedThe trend is NOT your friend. The trend used to be your friend, but it isn’t anymore.

I read somewhere that the stock market had become more mean-reverting and less trending in recent years, and I wanted to see if I could put that to the test. Many of the books I’ve read have been about trend-following investing. So if the trend is dead (or dying), I’d certainly like to know about it.

But how to test “trendiness”?

I decided to code an oscillator in AmiBroker. It works like this:

Any time the index price has a set of three ascending or three descending closes in a row, that little ‘trendlet’ sequence is counted. Longer runs of ascending or descending trends are recorded as multiple trendlets, as they should be, since a longer trend should have more weight than a shorter trend.

As you can see in the lead image, the brackets denote sets of three ascending or descending trendlets. Note the overlaps, and also note that one price breaks the set (marked “X”) and so doesn’t count as a trendlet.

Now count the number of trendlets over a moving lookback window, and keep a running total. The fragment above, if looked through a moving window of 12 bars, would have 6 trendlets.

Then I smooth the curve with a moving average, as otherwise it can be very jagged. We can then get an immediate visual sense of how an index (or stock or commodity etc) has changed its trendiness over time. For the longterm trendiness of indexes, I chose a lookback of 120 and a moving average smoothification of 120.*

Look at the S&P 500 index since the 1920s. The index’s trendiness has been much higher in the past than it is now. In fact, it appears to be highest in the 1950’s through the 1970’s. Since then, the market has gotten less and less trendy.

SPX trendiness
S&P 500 index from the 1920’s to the present, showing the changes in trendiness over the years.

My conclusion: trading systems and methods that rely on trend following are less likely to work – at least for stocks – than they were 30-40 years ago. Whether the market is getting  more mean-reverting, or just getting more random, is not addressed by this oscillator. Perhaps for a future post I’ll take a look at that.

One thing I find interesting about the trendiness of the S&P 500 is that the early decades of the 1900s have a lower value that is similar to recent times. The market has gotten more trendy and then less trendy over the past 100 years. I wonder why?

One other observation: the oscillation in the indicator for the S&P seems pretty regular. Is there some sort of seasonal component to trendiness, and can one exploit this by deploying trend-following systems only when trendiness is at a peak?

Below I have some other indexes displayed with their trendiness oscillators. The sets of data are much smaller than the S&P, but there’s definitely an evolution in all of them, either with the average level or the amplitude of the swings. Also note the general trendiness levels of each market. Some markets are simply more trendy than others. You might need to click the image to view it better.

DAX trendiness
DAX index.
EuroSTOXX 50 trendiness
EuroSTOXX 50 index.
Mexico trendiness
Mexican Stock Market index.
Nikkei trendiness
Nikkei index.
Russia trendiness
Russian Stock Market index.


SC trendiness
Shanghai index.

* smoothification: noun. The act of smudging a perfectly good set of number because you don’t like all the embarrassing peaks and valleys.

Do Good Days Follow Good Days?


Have you ever wondered whether one good day tends to follow another? I have, and I’ve done a little research.

I’m sure many times you’ve looked at a chart, or seen a list of the day’s top stock winners, and wondered “what if I bought this tomorrow? Would it go up, or would it go down?”

There are of course two opposing logical predictions you could make when you see a nice juicy green bar on today’s chart:

1. “Buyers are excited about this stock. It must be a good one, so it’ll keep going up tomorrow as well. I should buy at the opening bell.” This is a momentum strategy.

2. “Short-sellers will see this as an opportunity when the stock declines back toward its original level. And those who already own it will want to take profits while they can. So I should avoid going long in this stock, as it will likely snap back tomorrow.” This is a mean-reversion strategy.

Neither is wrong. Either one of these can happen, depending on many circumstances. But what’s the probability of one good day leading to another?

Let’s get our hands dirty with some data. But first, some parameters:

• I looked at all the stocks currently in the Russell 3000 index, from Jan 1, 2012 through May 18, 2015. The closing price at the time must have been greater than $2, and the 10-day average volume was greater than 50,000 shares/day. This gave me lots of data but avoided really illiquid stocks.

• I then defined my ‘signal’ day as being any day with a close that was 3% or more above the open. This is not the same as comparing two days’ worth of closing prices. You’re welcome to compare your own data on a close-to-close basis if you’d like!

• For each signal (and there were many thousands of them), I then looked at whether the close of the following day was less than its open. After all, the point is to decide whether we should pile in on the following day. Comparing consecutive closes is problematic from a trading standpoint, as it requires the intraday scanning of many tickers.

So basically, when we get a nice green bar on one day, do we get a nice green bar the following day? Or do we get a down day instead? Also, does the probability get better or worse depending on the size of the ‘signal’ bar? Below I’ve graphed the probability of failure, based on the size of the signal bar.

Screen Shot 2015-05-19 at 9.32.25 AM

Well it’s not good news. Taking no other conditions into consideration, you have a greater than 50% chance of having a loser day after a signal day. And the chances of having a down day (open to close) only increases, as the size of your signal bar increases.

But might there be any conditions that would make a stock more likely to ‘go green’ on that second day? So I decided to see if history tends to repeat itself. I then looked at the same data set, but filtered for stocks that had at least one instance of two days in a row where the close was above the open by 3% (within the last 60 bars).


Screen Shot 2015-05-19 at 9.30.29 AM

First, let me apologize about the scaling. It’s difficult to force two google charts to have the same scaling. But if you look carefully, you can see that the probabilities are pretty similar…until you get to the >16% range. For some reason the failure probability shoots up dramatically when you’ve already had a two-good-day sequence in the past. No idea why that might be.

A question comes o mind: do the number of signals in the past 60 bars make a difference? If a stock is prone to good behavior, will it affect the probability? To find out, I then sorted by the number of these previous two-day ‘bumps’ that occurred in the previous 60 bars. These signals could overlap: three days of 3% would count as two signals. On the chart below I’ve called these signals “bumps”. And this is what I got:

Screen Shot 2015-05-19 at 9.44.07 AM


For the first time, the probability of failure has dipped down below 50% in some cases. Specifically, a stock that has generated 5, 6 or 8 signals in the previous 60 bars is slightly more likely to have an up day after we get a signal.

Yes, I see it too. WTF is going on with the 7-bump set of data? No idea whatsoever. There were over 1000 samples in the 7-bump set, so it’s not due to some outlier phenomenon. Even the 8-bump set had >500 samples. Above that, the data gets patchy so I would ignore the last bar.

So what does this mean? I think it ties in well with my earlier research, in that the recent history of a stock’s performance can be an indicator of future behavior. When designing a trading system, you might consider this aspect for filtering the most likely candidates to trade.

Using Market Advance/Decline Divergence to Predict Short-Term Direction

For a few months now I’ve been tracking my own market breadth/diffusion index by hand in a spreadsheet. I realized a few days ago that I could automate it and also create historical composite data by using certain commands in AmiBroker. Since then I’ve been ruining my eyesight gazing at charts and spreadsheets, and I’ve come up with something that looks interesting.

Here’s a chart to prove I’ve been working hard:

Screen Shot 2015-04-14 at 3.11.28 PM

Here’s what I do:

For the set of Russell 3000 stocks, each day I have AmiBroker count up the number of tickers that closed at least 4% above their closing price from yesterday, as well as the stocks that closed at least 4% down. Then I calculate the ratio of advancers to advancers+decliners. Ratio=A / (A + D). That’s the column on the far right of the spreadsheet above.

I then look for divergences between this ratio and the closing price of the S&P 500. Most of the time it’s in sync, but every once in awhile it diverges. The S&P will go down while the ratio goes up, and vice versa.

Screen Shot 2015-04-14 at 2.54.35 PMThe upward red lines show potential bullish divergence, where the S&P went down and the ratio went up. The downward red lines show the opposite. The blue line is the closing price of SPY between 9/2/2014 and 4/13/15.

Ok so yes there’s a divergence from time to time, but does it hold any predictive value?

Very possibly!

60.00% of the divergence signals are followed by an up day for the S&P. Hmm, that could be useful, right? Now keep in mind I’ve only done this for the period in question, so it’s just a preliminary dip of the toe in the statistical water.

And I’m sure you’re asking yourself: is this actually better than pure chance? What if the market had “up” days 60% of the time? I’d better measure that as well.

Turns out during this period of time, the S&P closes up from the previous day 51.30% of the time. So 60% vs 51% seems pretty significant (pending further testing).

The reverse wasn’t true however. The negative divergence signal was predictive only 47.62% of the time. Perhaps the predictive power is dependent on the longer-term trend.

Screen Shot 2015-04-14 at 2.55.55 PMI don’t know if this measurement would be strong enough to trade SPY on its own, but perhaps it offers some short-term market-timing abilities when used in conjunction with other techniques. For those of you who like to crunch numbers, it’s something to explore.

Trading the Gaps: Are they Good For You?


I’ve read about a variety of techniques out there for “trading the gap”. A stock opens much higher than the day before, usually showing excitement over some news or earnings event, and then you make your move.

Some techniques use this gap signal as a “buy” as it could signal the start (or continuation) of a trend. Others see this as a signal to sell (i.e. “fade the gap”), as it could be an over-extension and turn into a mean-reversion trade.

I’ve noticed – and I’m sure you have too – that big gaps seem to behave differently than small gaps. So I got to wondering what the statistics might be for different size gaps. And voila, I have some data for you! The results are interesting.

First off, some definitions. What’s a gap? Well it could be defined as an open that is higher than the high of the day before. But if the stock trades down below the previous day’s high, that doesn’t feel like much of a gap. So I’ve defined a gap as a low that is higher than the previous day’s high. It can be as little as $0.01 difference, or as great as whatever…40%? Double? We want to look at all sorts of gaps.

I took Yahoo historical data from 2000 to the end of 2014, for the NYSE and NASDAQ. No filtering for any market conditions or anything else except: the close of the day in question had to be >$15, and the average 10-day volume had to be >100,000 shares. Low-priced or low-volume shares behave less predictably, so I’ve left them out.

I filtered out results that were obvious errors (it’s not the cleanest of data), and ended up with a mere 115,394 data points. Erroneous data usually shows up as massive gaps, so I probably was able to remove most of the offenders.

I took note of a few things:

– the percentage gap between the current day’s low and the previous day’s high.

– the opening price

– the closing price

– the closing price of the 5th day after the ‘gap’ day

My trading hypothesis here was to spot a large gap in intraday trading, and then make a decision to buy at the close of that day. The stock would be held through the fifth day and then sold at the close (with day 1 being the day of the gap). While you can’t know for sure the exact high or low for the day until after the close, you can usually get a good sense for most trades within the last 15 minutes of the day.

That seems a reasonably practical system, although I’m not fleshing out anything beyond that at the moment. This is just hypothetical, to see what sort of gaps yield what sort of results.

I could have divided up the data into vigintiles, but that would have yielded results that would be more complicated to work with in real life. It’s much easier to ask “is this gap between 5% and 6%?” than it is to ask “is this gap between 1.0045% and 2.3311%?” In the real world, we’ll be looking for nice round numbers to simplify our decisions. So I use round numbers for the gap percentages to divide the data up into groups. The vast majority of gaps are of course in the tiny-sized realm, under 1%. As the gaps get bigger, the data points get fewer, and the reliability and/or statistical meaningfulness gets lower.

So each gap-percentage group averages the gain/loss of each trade within that group, to yield a single number for that group. A positive number does NOT mean there are more winners than losers in this group, only that the average of all the trades is positive.

So first I looked at the overall results for all gap-day closes through the close of the 5th day. Note that the percentage groupings do NOT include the lower groups in the average. For labeling purposes I’ve used “<5%” but that does not mean “0% to 5%”. It means “less than 5% but greater than the next lowest group”. Not cumulative, in other words.

gap-up-close-5daySo without regard to whether the “gap day” turned out to be an up day or a down day (comparing the close to the open), we get the above chart. The conclusion: buying at the close and selling at the 5th day’s close is likely to be a losing proposition unless your gap is at least 7% or greater. The dip for the range of 10-15% is odd, so perhaps we would focus on gaps that are between 7% and 10%.

You may have noticed in your chart-gazing that some gaps are really big but then fall throughout the day as sellers take their surprise profits. And other stocks just keep going up and up all day. So is there a difference if we buy at the close of a ‘green’ day rather than a ‘red’ day? Let’s take a look:

For "up" days, where the close is higher than the open.
For “up” days, where the close is higher than the open.


The chart above shows what happens when you buy at the close of a “green” day and sell at the close five days later. Basically it’s a bad idea to do this for most percentage gaps! Why gap values between 7-8% show an average gain while the rest of the graph is negative (ignoring the infrequent >15% trades) is a mystery. Possibly erroneous data, so I wouldn’t blindly trade it without further investigation. But overall it looks like green-day gaps only lead to misery unless you’re shorting the stock.

Ok so what if there’s a gap up, but then the day closes in the red? Is there an opportunity there?

For "down" days, where the close is lower than the open.
For “down” days, where the close is lower than the open.


Sure looks like there might be. Between 5-6% is still a losing (aka “shorting”) proposition even with a down day, but get into the 6-15% range and you’ve got a winner. Note the average gain/loss for the 7-8% range here, at just under 1.4%, is higher than any other percentile on any of the other graphs.

So from this very basic data, without filtering for any other conditions in the stock or the wider market, there are two areas that warrant research: shorting any gap that is in the 5-6% range, or going long any gap in the 6-15% range that also has a “down” day as the first day.

If I get around to it, I’ll take a further look at some other variations, like buying at the next day’s open, or setting limit orders etc. For example, what happens if in the following few days the gap is “filled”, i.e.  the price drops down below the low of the gap day? Will it go back up? Maybe if I don’t get lazy or distracted, we’ll find out!