Optimism is hardly the order of the day in Washington. But even if you think that a cold-shower dose of reality is what the politicians in this town really needed, the situation is more hopeful than most of the commentary here would suggest.

By dramatically signaling the end of the ''morning in America'' euphoria of the middle Reagan years, the stock market may have done the country and the world a huge favor. The reaction on both ends of Pennsylvania Avenue suggests that the message has been heeded, perhaps in time to head off the economic collapse that such a crash in equity values has historically signaled.

Many signs suggest that there is a good deal of strength and resiliency in the economy. The latest figures on the gross national product and consumer prices suggest that we are still enjoying healthy growth without inflation. If the politicians here and abroad can take the well-recognized steps necessary to adjust their fiscal, monetary and trade policies, the prospect is far from bleak.

For the United States, the overdue imperative is disciplining the federal budget deficit. And that requires that Congress and the president abandon the myth that they can sit on their prerogatives and force someone else to make the hard decisions.

Finally, it appears they are ready to face the music.

President Reagan has climbed off his high horse about taxes and agreed that revenues can and must be part of the bargaining. For their part, the majority Democrats and minority Republicans on Capitol Hill have tacitly conceded that the Gramm-Rudman-Hollings ''automatic sequester'' is a poor substitute for the tough political choices that must be made to get control of federal spending.

It's about time.

Reagan has squandered almost five years of strong economic growth, during which time we could have closed the budget gap created by his 1981 decision simultaneously to reduce tax rates and put defense spending on an accelerated buildup. As deficits soared to previously unknown levels, Reagan, like a broken record, intoned, ''No more taxes.''

In fact, higher tax rates did not have to be the heart of the solution. A good economic case could be made for holding down rates as far as possible during those years in order to spur economic growth. But by insisting that taxes could not even be discussed in bargaining over the budget, Reagan substituted dogmatism for realism -- thereby inviting the congressional defenders of the military and civilian pork barrel to be equally adamant in protecting their own pet spending.

The most conspicuous victim of his stubbornness was the Senate budget compromise of 1985, hammered out by Bob Dole and immediately undercut by Reagan. The failure of that effort set the stage for the Republican loss of the Senate majority in 1986. And that in turn has left Reagan fighting defensive battles on everything from the composition of the Supreme Court to the American commitment in Nicaragua and the Persian Gulf. Expensive dogmatism, indeed.

The scuttling of that 1985 Dole-engineered budget also led to passage of the Gramm-Rudman-Hollings bill, as an embarrassed Congress sought a fig leaf to cover its nakedness on realistic budget policy.

If Reagan can be blamed for dogmatism on budget matters, Congress stands equally guilty of escapism. Sen. J. James Exon of Nebraska, a conservative Democrat, who, like other former governors of both parties, can't stomach the hypocrisy that passes for budget policy in Washington, said it best when Congress was passing its latest cop-out version of Gramm-Rudman-Hollings.

''The entire Gramm-Rudman process actually delays serious action on the deficit,'' Exon observed. Noting how the 1986 budget ''reconciliation bill . . . was loaded with spending shifts, one-time asset sales and accounting gimmicks . . . which technically met the Gramm-Rudman targets,'' Exon said:

''Rather than force action, the Gramm-Rudman process fakes action. After two years of operation, by and large, Gramm-Rudman has not worked. The new version of the law does not bring with it a new promise of deficit reduction. If anything, it pushes difficult decisions away from this Congress and President Reagan onto the next Congress and the next president.

''It is a way for Congress to congratulate itself for having fiscal courage without making a single decision on the spending and revenue issues which produce the debt and deficit.''

On Sept. 23, when Exon delivered this brutally accurate assessment, Congress chose to join the president in playing ''let's pretend.'' Gramm-Rudman-Hollings passed with bipartisan majorities, and Reagan signed it into law.

Now both the president and Congress admit what the markets knew: it's a charade. What Exon called ''the nuclear nightmare of the president's fiscal policy'' has exploded. And in the new realism, there may be time for a successful rescue effort.