NEW YORK, JAN. 6 -- The stock market closed with a modest gain today, extending its early 1988 rally through a third session.

Meanwhile, stock prices advanced strongly on most foreign markets, particularly Tokyo, where the key Nikkei Index posted its second-largest advance ever.

The Dow Jones average of 30 industrial stocks, up 92.67 points in the year's first two trading days, added another 6.30 to close at 2037.80. Gainers outpaced decliners by 7 to 5 on the New York Stock Exchange, where volume totaled 169.74 million shares, down from 209.52 million in the previous session.

The market's advance Monday and Tuesday was widely attributed to encouragement over a rebound by the dollar in foreign exchange.

The dollar's recovery continued today, bolstered in part by a Japanese television report that the United States, Japan and West Germany had privately agreed to hold the dollar within a specified range of 130 to 140 yen. Analysts said, however, that many investors remained skeptical about the durability of the dollar's rise.

They also said stock traders were reluctant to chase after the recent Wall Street rally, questioning whether the market could put together a sustained advance so soon after its steep fall in October.

Nevertheless, the swing has carried the Dow Jones industrial average to its highest levels since Oct. 19, when it stood at 2246.74 just before taking a 508-point drop that day.

The recovery of the dollar was cited as a factor in Tokyo, where the 225-issue Nikkei average rose 1,215.22 points to close at 22,790.50. The strength in Japan was reflected in Hong Kong, Sydney and Singapore, where prices also advanced strongly.

(The Tokyo stock market lost modest ground in the morning session Thursday. The Nikkei index shed 113.87 points to close the morning session at 22,676.63.)

In London today, meanwhile, stocks ended mixed in active trading, with shares closing well below their highs of the day. The Financial Times 100-stock index, which had been up as much as 20 points earlier, closed off 2.5 to 1787.1.

The day's largest percentage gain among NYSE issues was IU International, which jumped 4 5/8 to 18 5/8. Neoax Inc. began a $17.50-per-share tender offer for IU's stock.

Grand Auto, traded on the American Stock Exchange, rose 4 3/8 to 15. On Tuesday the company said it had agreed to be acquired by Paccar Inc. for $16 a share.

Among actively traded blue chips, International Business Machines gained 1 to 122 7/8; Union Carbide 1 5/8 to 24 3/8, and General Electric 1/4 to 47.

Sterling Drug added 2 1/4 to 76 3/8 on top of a 17 1/4-point jump Tuesday on word of a takeover bid from F. Hoffman-La Roche.

Ashland Oil fell 1 7/8 to 54 5/8. The company said it may not have had proper approval to fill a storage tank that collapsed over the weekend, causing an oil spill in two rivers near Pittsburgh.

The NYSE's composite index of all its listed common stocks edged up 0.28 to 144.28.

Nationwide turnover in NYSE-listed issues, including trades in those stocks on regional exchanges and in the over-the-counter market, totaled 199.04 million shares.

Standard & Poor's index of 400 industrials rose 0.59 to 300.30, and S&P's 500-stock composite index was up 0.26 at 258.89.

The Nasdaq composite index for the over-the-counter market rose 2.65, to 346.72. At the Amex, the market value index closed at 275.00, up 3.23.