Stocks wavered throughout the day but managed to eke out modest gains Monday as oil prices rose. Investors bought drillers, refiners, and other energy companies as the three-week rise in crude continued. Six of 10 industry sectors in the Standard & Poor’s 500 rose, helping the index extend its winning streak to a fifth day. Still, it was a bumpy day. ‘‘Today’s volatility is mostly about a little profit-taking and taking a pause after such a strong advance in recent days,’’ said Jim Paulsen, chief investment strategist at Wells Capital. Shares of consumer products and technology companies fell. With no big US economic or earnings announcements, news from abroad appeared to drive much of the trading. The price of iron ore jumped 17 percent on news over the weekend that China plans to run up its deficit to stimulate its economy. China is the world’s largest buyer of this raw material for steel, and mining companies soared on the news. China also lowered its official growth target this year to 6.5 to 7 percent. The slowdown has been rattling markets, although fears that the trouble could spill over into the US economy have eased in recent weeks.