By Caroline Valetkevitch

NEW YORK (Reuters) - U.S. stocks closed higher on Friday in a modest but broad-based advance as Donald Trump was sworn in as U.S. President, marking the first time in more than 50 years that a new commander-in-chief has been welcomed by a rising equity market on his first day in office.

In his speech, Trump said U.S. policy will be to buy American and hire American, reiterating what he had said many times during this campaign for the White House.

Some investors said the comments reinforced concerns about potential protectionist trade policies. Indexes pared gains during his speech and ended off the highest levels of the day.

However, the rally in stocks since the Nov. 8 election had stalled in recent weeks as investors awaited clarity on his plans to boost the economy. All three major indexes ended with losses for the week.

"We're now trading off of reality rather than hope, and it's natural to be a bit more cautious when we make that transition," said Brad McMillan, chief investment officer for Commonwealth Financial in Waltham, Massachusetts.

The S&P 500's 6.2-percent gain since the election is one of the best performances for the American stock market for any presidential transition period of the modern era.

Former President Barack Obama's transition period, which came amid the throes of the 2008 financial crisis, overlapped a 15.5 percent fall for the S&P 500 from his election to the day of his 2009 inauguration. Yet he presided over the second-best run for the stock market under any president since Dwight Eisenhower.

The Dow Jones Industrial Average <.DJI> snapped a five-session losing streak, closing up 94.85 points, or 0.48 percent, to 19,827.25. The S&P 500 <.SPX> gained 7.62 points, or 0.3 percent, to 2,271.31 and the Nasdaq Composite <.IXIC> added 15.25 points, or 0.28 percent, to 5,555.33.

The last time when either the S&P or Dow rose on the day a new president was inaugurated was Jan. 20, 1961, when John F. Kennedy was sworn in to succeed Eisenhower. The S&P gained 0.32 percent and the Dow added 0.31 percent; the Nasdaq did not yet exist.

The first day aside, the coming month might not be as rosy. The S&P 500 has fallen by a median 2.7 percent in the month after each new president has taken the keys to the White House since Herbert Hoover in January 1929, according to a Reuters analysis.

Trump also loomed on the earnings front. Shares of Kansas City Southern <KSU.N> rose 4 percent even as it reported a lower quarterly net profit that missed Wall Street estimates. A historic drop in the Mexican peso <MXN=> after Trump's election affected the regional U.S. railroad's operations in Mexico.

Among other gainers, Merck <MRK.N> rose 3.6 percent to $62.53 after Bristol-Myers <BMY.N> said it would not seek accelerated U.S. approval for a combination of its two immunotherapy drugs as an initial treatment for lung cancer, giving Merck an advantage in the lucrative market. Bristol-Myers' stock fell 11.3 percent.

About 6.6 billion shares changed hands on U.S. exchanges, higher than the 6.1 billion daily average for the past 20 trading days, according to Thomson Reuters data.

Advancing issues outnumbered declining ones on the NYSE by a 1.76-to-1 ratio; on Nasdaq, a 1.58-to-1 ratio favored advancers.

The S&P 500 posted 19 new 52-week highs and seven new lows; the Nasdaq Composite recorded 85 new highs and 33 new lows.

(Editing by Nick Zieminski and James Dalgleish)