If ever they give an Oscar for bad timing, there will be no need to ask for the envelope. President Daniel Ortega of Nicaragua will be the winner, going away.

He laid heavy claim to the title last April, when, within days of a hard-won House of Representatives vote against aid to the contras, he took wing for Moscow, occasioning anguished cries of "betrayal" from those who had nervously taken up for him, and "I-told-you-so" from those who all along said he is an agent of the Kremlin.

But he cinched the cup last week, when on the eve of a visit to the United Nations, he announced a state of emergency in Nicaragua, setting off a new frenzy of hand-wringing and self-righteousness.

It can be argued, although few have, that Ortega, being the elected head of a sovereign nation, however impoverished and down at the heels it may be, can do as he pleases in what he sees as his country's interest. Despite President Reagan's overheated representations to the contrary, we do not own Nicaragua, and its Marxist leanings are really none of our business, since Nicaragua's ability to "export revolution" is a fiction invented by those who want Ortega to say "uncle."

And it is further arguable that the reasons given by Ortega, which are vague and flimsy, are totally related to his principal problem, which is a U.S.-backed revolution against his shaky regime.

But what the move shows most is that Ortega has not lost his compulsion to play into Reagan's hands. Countless congressional delegations have gone to Managua to plead with him to employ a slightly less leaden touch and to give them a break in their efforts to defend his right not to be overthrown. They are sadly concluding that he has developed a taste for spitting in Uncle Sam's eye.

Quite apart from the fact that Ortega has come to the U.N. as a culprit instead of as a figure of some sympathy, he chose a moment when things were going rather well for Nicaragua in public opinion, mostly because world attention has been elsewhere.

The Nicaraguan ambassador, Carlos Tunnermann, recently noted that not a single country has joined in the trade embargo imposed by the United States -- not even El Salvador, which alone voiced support for the idea. In the World Court, where Nicaragua has lodged a complaint against the U.S. for the mining of its harbors, the U.S. has looked petty for its denial of court jurisdiction over "a political matter."

The verdict, which is expected to go Nicaragua's way, is pending, but Ortega has taken pains to see that the victory will be muddied.

None of the individuals or groups who stick up for the Sandinistas, or at least their right to exist, can justify the crackdown. Rev. Joseph Eldredge of the Washington Office on Latin America calls it "perplexing and discouraging."

Paul Reichler, the Washington attorney who is presenting Nicaragua's case in the World Court, says the timing is "not the best."

The State Department doubtless knew that Ortega was in the way of being warmly received in some quarters in the U.S. That is almost surely why it withheld a visa permitting him to travel outside New York until late last Friday -- when it was too late for him to accept speaking invitations from some half-dozen American cities, including Seattle, St. Louis and San Francisco.

The Socialist Mayor of Burlington, Vt., Bernard Sanders, went to Nicaragua last July and asked Ortega to come to a Vermont town meeting. Sanders thought it was "important for Ortega to communicate directly with the American people." He thinks the Ortega crackdown is "obviously not good."

"Still," he says, "I think it's kind of ironic that we're so upset, when the president has been telling us for two years that this is a totalitarian, terrorist government where people had no civil rights anyway."

Mayor Don Fraser (D) of Minneapolis, who deplores U.S. policy in Nicaragua, wrote a letter to Ortega seconding an invitation from a church group, thinks Ortega "may have given up on the U.S." Fraser is more interested in the fact that the letter he sent to Ortega through the Nicaraguan Embassy seems to have been intercepted by the government.

Supposedly, there has been a lull in the fighting between the Sandinistas and the contras, who are once again receiving U.S. funding. Ortega, it is said wanted to clear the decks before a last, conclusive assault, and he wished to curb his most obdurate and powerful local dissenter, Cardinal Miguel Obando y Bravo, who is leading an antidraft campaign.

Whoever he was aiming at, Ortega, once again, seems to have shot himself.