A hurricane blew through financial markets yesterday with traders reporting conditions close to chaos at points in both the stock and foreign exchange markets.

The Dow Jones Industrial Average surprised nearly everyone by closing the day up 5.80 points, its best showing in nearly three weeks, after dropping more than 17 points during the first hour in what was described as "an emotional selling climax" by some analysts.

The Dow had dropped more than 90 points in the last two weeks.

Volume of 59.6 million shares was the third highest in New York Stock Exchange history.

The gain in the 30 Dow industrials, however, masked a continuing widespread decline for smaller issues that has cut 25 percent to 50 percent from many market values in the last two weeks. On the Big Board, 442 stocks ended the day higher while 1,292 declined.

The dollar, meanwhile, continued its free fall which began last week following President Carter's speech on his new anti-inflation program. The 2 percent average drop was described as one of the worst ever for the dollar.

"We're in a state of total chaos," said a foreign exchange specialist for a leading U.S. bank. "Traders have been reduced to an operation where they'd rather not trade at all, but we just can't close down. Leading indicators up 0.9 percent. D9 I think these markets are totally crazy but, unfortunately, in default of any action from Washington to stop it - if such an action had credibility in the first place - it's just going to go on."

The dollar set record lows against major currencies and closed the day's trading in New York at the bottom - worth only 1.71 West German marks, 1.47 Swiss francs and 176.8 Japanese yen.

For the first time in four years, the British pound sterling was worth more than $2.10 - rising dramatically yesterday - and the dollar dropped below 4 French francs.

In a further reflection of the lack of confidence in the U.S. currency, gold rose to a record $242.75 an ounce in London at the afternoon fixing, up $8.25 for the day.

The flight from the dollar also spilled over into strong demand for precious metals in U.S. commodity markets.

And in the bond markets, sharply rising interest rates took their toll, with many issues registering retreats of one-half point and more.

Because the Treasury must raise $11 billion this week in the debt markets, there was no expectation of further credit tightening by the Federal Reserve Board until at least Friday - even if the dollar continues to plummet.

While the dollar and interest-rate news background remained negative, stock market analysts attributed the dramatic first-hour drop to margin calls recevied by individual investors over the weekend.

"The tendency seems to be to answer the calls by selling, rather than by putting up more money," commented Robert Farrell, manager of Merrill Lynch's market analysis department. He said yesterday's selling climax "may be the worst for some stocks." But he predicted that, for the market as a whole, the rebound probably will be limited to a few days and that the decline then will resume.

First-hour volume on the NYSE was 15.6 million shares, the fourth heaviest on record for the opening hour. And after that, the Dow stood at 788.98, off 17.07 points.

Among the active blue chips, Sears Roebuck lost 5/8 to close at 20 1/2; UAL Inc., which announced record third quarter earnings and an option on 69 Boeing jets worth $2.2 billion, was up 7/8 to 32 1/4, and America Telephone & Telegraph dropped 1/4 to 60 3/4.

The American Stock Exchange index was down 2.58 to close at 138.73. At one point, it had been off by more than seven points - which would be the equivalent of a 40-point drop on the Dow. Some 131 issues grained, and about 718 were lower.

And the NASDAQ composite index of over-the-counter stocks finished off 2.85 points to 112.40.