NEW YORK, NOV. 18 -- The stock market rallied near the close of a drifting session today as investors awaited developments in the negotiations toward a federal budget plan. The dollar fell as a result of nervousness about the budget negotiations.

Analysts said many traders were shying away from the market pending some sort of agreement between the Reagan administration and congressional leaders on measures to shrink the budget deficit.

The Dow Jones average of 30 industrials, down about 25 points at its lowest levels of the session, closed with a 16.91 gain at 1939.16.

Advancing issues outpaced declines by nearly 2 to 1 on the New York Stock Exchange, with 1,030 up, 522 down and 423 unchanged. Big Board volume totaled 158.27 million shares, up from 148.25 million in the previous session.

The dollar fell in response to pessimistic comments from congressional leaders about the negotiations to reduce the budget deficit, according to Robert Ryan, senior foreign exchange trader with Irving Trust Co.

The currency markets remain highly sensitive to such comments, said Jack Barbanel, a vice president at Gruntal & Co. "Everyone's expecting to get this wonderful budget package, but if it's weak or nebulous I think the dollar is going to start heading south again," Barbanel said.

The dollar fell sharply in Europe on pessimism over the budget deficit, but bounced back somewhat toward the end of the session to close at 1.6865 marks, down from 1.6950 late Tuesday. In later New York trading, the dollar fell to 1.68475 marks from 1.6906 marks late Tuesday.

The dollar closed in Tokyo at 136.05 Japanese yen, unchanged from Tuesday. In later London trading, it fell to 135.55 yen, and it slipped in New York to 135.50 yen from 135.595 yen.

The pessimistic comments from Capitol Hill prompted some selling in the stock market, but the decline failed to gather much momentum.

Gainers among the blue chips included Exxon, up 1 at 41 1/2; International Business Machines, up 5/8 at 118 3/8; General Electric, up 1/2 at 45 1/2; American Telephone & Telegraph, up 3/8 at 29, and Coca-Cola, up 1 at 39 1/8.

GTE led the active list, up 1 at 36 on turnover of more than 5 million shares. The company said it expects losses incurred by US Sprint Communications, in which it has a joint-venture stake, to continue to narrow.

The NYSE's composite index of all its listed common stocks added 1.37 to 137.58.

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

Standard & Poor's index of 400 industrials rose 3.10 to 281.15, and S&P's 500-stock composite index was up 2.51 at 245.55.

The Nasdaq composite index for the over-the-counter market gained 1.47 to 318.22. At the American Stock Exchange, the market value index closed at 246.85, off 0.57.