Yesterday, the S&P 500 (^GSPC 0.87%) index managed to set a new record. The previous record closing price for the index was set in 2007 at 1,565, but when the closing bell rang yesterday, the S&P 500 had hit 1,569. Just a few weeks ago, the Dow Jones Industrial Average (^DJI 0.67%) broke its previously set record high, and has since been setting new ones.

A few media outlets have recently been telling investors that even though the Dow and S&P 500 are trading at all-time highs, they are still below their records when inflation is calculated. My Fool colleague Morgan Housel recently demonstrated how these claims are, in fact, completely incorrect. Well, perhaps not completely but they are still false. He explains that when adjusted for inflation, the Dow is still below its record set in 2007. But when you add the dividends that companies have paid since then, the 2007 record doesn't stand a chance.

So while the headlines are telling you that the markets are now at their all-time highs, that isn't completely true. And while we are on what's true and what isn't, when you hear that the markets are overbought and are due for a pullback, well, that's not necessarily true, either.

If we look at what has truly caused the Dow and the S&P 500 to move higher, we must look at what the indexes themselves are made of -- i.e., individual companies. The Dow consists of 30 of them. The index moves higher when the shares prices of those companies increase, but as the name says, it's an average. If 10 companies' shares prices move lower but those of the other 20 move higher, the index will move higher. While not every stock in the Dow is evenly weighted, it usually works out that the majority rules.

So even though the Dow, as a collective whole of 30 different stocks, is at its all-time high, that doesn't necessarily mean all of its components are at their all-time highs or, better yet, that their shares prices can't go any higher.

In the short term, share prices are affected by a number of factors: the weather, breaking news, legal issues, mergers and acquisitions, or even just rumors. But, in the long run, earnings are king. A company's past earnings and future projected earnings rule and dictate shares prices on a year-to-year basis. Therefore, when earnings go higher, share prices move higher. But as we have seen before with the dot-com bust, if investors believe future earnings will be higher than they are today, shares prices also rise.

What's this all mean?
Now that the Dow and S&P 500 are at their all-time highs, the only way they can move higher is if the share prices of their underlying components move higher.

Many of my colleagues here at the Fool and I believe this can and will happen. John Maxfield recently wrote about why he believes shares of Bank of America (BAC 2.06%) will double within the next 18 to 24 months. John has been a longtime bull of the banking industry, and he feels that even though the stock rose more than 100% in 2012, it still has a long way to go until it's fairly priced.  

At the beginning of the year, Anders Bylund bought shares of Intel (INTC 0.61%). At the same time, Steve Heller gave five reasons to buy shares of Intel. Intel was then trading at just above $20 per share, and the stock has only risen 5.89% year to date after falling 16% in 2012. Steve noted that Intel's five-year earnings growth rate is 22.8%, and he believed at the beginning of the year that shares were undervalued by 61%. So even after the 6% rise this year, Steve thinks there's a potential 55% upside still left in the stock price, and that's not even counting Intel's current 4.2% dividend yield.  

Travis Hoium noted just this week that Home Depot (HD 0.22%) is directly tied to the housing market, and even though the stock is flirting with its 52-week highs, the share price will likely continue to move higher if the housing market continues to strengthen.

Final foolish thoughts
While I could continue to go on about all the different Dow components that have the potential to continue to move higher, I will leave you with one last thought. If you buy stock in a stable company tomorrow and you plan to hold on to it for a few years, would you sell just because the share price hit an all-time high? Why, then, would you sell just because the index that simply tracks a number of stocks hits its an all-time high?