The Dow and S&P 500 closed out their fourth week of losses with a small gain on Friday, but only with the help of a weaker dollar boosting metals prices and basic materials stocks.

The Dow Jones industrial average <.DJI> gained 38.82 points, or 0.31 percent, to end unofficially at 12,441.58. The Standard & Poor's 500 Index <.SPX> rose 5.41 points, or 0.41 percent, to finish unofficially at 1,331.10.

The Nasdaq Composite Index <.IXIC> advanced 13.94 points, or 0.50 percent, to close unofficially at 2,796.86.

(Reporting by Edward Krudy; Editing by Jan Paschal)