Sometimes when you're trading stocks it's like you have the Midas touch and every position you put on makes gobs of money. Every breakout play shoots for the moon. Even the lamest of the lame stocks in your shorts list take flight and no matter which one you buy it all just works. It's like magic.
And then, well, err... there are those other times... All the promising breakout plays turn in to bull traps. Every low-volume pullback you enter keeps on pulling back, right on through your stop. It all just fails, no matter how good the setups and which direction you trade. Nothing works and for you, at least, the Gods of Technical Analysis seem to have forsaken you.
Knowing the difference between these two scenarios and recognizing when conditions are not conducive for profitable trading is a very important skill to acquire and one that I'm still working on. Most of the time you can see these "bad times" on the indices after they've already been underway for a while because the price action just chops sideways. Attempting to trade anything but the shortest timeframes in a choppy market is a lesson in futility.
Once I realize what's going on I'll usually stop trading but only after I've given back a sizeable portion of my gains. A good example of this is what happened after the intermediate-term bottom this past July: I caught the bottom in some tech and consumer discretionary stocks, rode them upwards for some decent gains and then watched them get stopped out one by one. A couple of subsequent trades also failed even though the setups looked perfect. By the time it was all over I'd given back over half my profits. Frustrating!
Six weeks later it's painfully apparent that immediately after the initial rally the market shifted into chop suey mode. It sure would've been nice to know that at the time!
Okay, so how do you know when a rally is souring?
There are a lot of ways, but the easiest method is to gauge the market breadth via the Advance-Decline line on stockcharts.com:

When the A/D Line failed to make a higher-high after July 28th (red arrow) it was a sign that the rally had soured. Advancing issues were not significantly outnumbering the declining issues. Strong rallies are not built on that relationship. Tightening up stops and not opening new trades around that time would've been prudent and saved me a good deal of my profits.
There are other ways of quantifying the health of a market, all of which have their strengths and weaknesses. One very simple method is to just watch the relative performance of the major indices. If you see divergences between the Dow, S&P 500, Russell 2000, and the Nasdaq then something's wrong. In a healthy market the tide should raise all the boats, not just a few large stocks or one or two sectors:

Get a load of all the chop post mid-July bottom in the above chart of the S&P 500 versus the Dow Jones Industrials, Nasdaq Composite, and Russell 2000 indices. If you'd known ahead of time which sectors or stocks to be in then you could've done well but how could you have known that before the fact? I mean, really known? You couldn't have, not with any degree of certainty, anyway.
My new favorite breadth indicator is simply the relationships between the different market sectors via their ETFs and how they're moving in relation to each other. If you adjust the timeframe so that the chart starts around the time of the mid-July bottom you can see that except for a couple of sectors things weren't working well right from the start:

On the other hand, the previous two months were great times to trade -- provided you were willing to go short or buy inverse index ETFs:

Everything was pretty consistently down, an indication that the money tide was flowing out of equities, taking prices down with it. Trying to trade against that force would've been unproductive at best, tantamount to salmon swimming upstream. It can be done but it's much harder than just going with the current.
What I'm getting at here is that you to have to recognize when money is flowing into and out of the market as a whole and ignore the minor sub-themes that inevitably fail. In other words, you need to be watching the tides and not the ripples on the surface of the water.
Fortunately, actually doing that, and doing it in real-time, is easier than you'd expect. This post is getting very long so I'll leave the description of my new indicator for another post. In the meantime, go study the Sector PerfChart and think about correlation coefficients.