Source: ExxonMobil investor presentation.

Hindsight is always 20/20, but many of us shouldn't have been surprised that the boom in American oil production would eventually lead to a drastic drop in oil prices. We can't just add 4.5 million barrels per day of new production to the global supply in a matter of a few years without there being some sort of consequence on price. Yet for years we -- myself included -- got caught up in the hype of booming production without any real consequence because oil prices remained high up until about a year ago. 

What is more discouraging more than anything else is that we still seem to forget from time to time that oil companies sell commodities that go through boom-and-bust cycles just like every other commodity, and trying to catch the waves of the booms before the wave breaks on your porfolio can be speculative at best. 

So rather than trying to get in and out of oil companies with perfect market timing -- a nearly impossible task -- here are two important qualities that you can look for when investing in oil companies that will help you ride through the good times and bad. 

A competitive advantage can go a long way in a commodity market
It's hard for an oil company to really distinguish its offerings from its competitors. At the end of the day, they are all selling oil and can't really up-charge for its product more than another, and the price of oil hasn't exactly been the model of stability for as long as we have been digging holes in the ground to get it. 

Considering that oil production is almost always a race to the bottom of the cost curve, it can be really hard to carve out a competitive advantage in this space. For example, integrating components of oil value chain into one company like the integrated majors -- you know, the ExxonMobils and Chevrons of the world -- allow them to see one part of the business flourish while the other stumbles and vice versa. While they may not lead to massive gains as oil prices skyrocket, they also don't see their prospects get completely wiped out by a decline, either. 

This isn't the only kind of competitive advantage, of course, so look for things that an oil company can do to rise above the rest.

Disciplined capital allocation applies to all market conditions
Quite possibly the biggest fault we saw during over the past year was that so many oil companies spent almost outlandish amounts of money to grow their production portfolios. The underlying theory to this plan was that each of these oil companies could grow into their spending levels through higher production, so they could take on debt now and use future cash flows to pay off those debts once they were producing huge amounts of crude. 

What this went to show was that this theory is very flawed, because the oil market can take a turn for the worse on a dime and outspending your cash inflows even when times are good will come back to haunt you when things get tough. 

Also, there is an immense amount of value in an oil company's capital expenditure habits. Even with higher oil prices, this is a difficult endeavor because the oil and gas business is extremely capital intensive. Companies that will be the most successful over the long term are the ones that can spend within their cash-generating capabilities today and resist the temptation to drill at all costs to grow production when times are better.  

What a Fool believes
Investing in oil companies isn't an exact science. Oil itself is a commodity that holds so much geopolitical sway and the price can be influenced by hundreds of factors on any given day around the world. Being able to wrap your head around all of them at once and then being able to determine which way oil prices will go is impossible. Fortunately, you don't need to be an oil price savant to invest in this space. Rather, identifying oil companies that carve out a competitive niche and display a high degree of capital discipline and then investing in them over the long term should give you a higher level of success.