Ronald Reagan is putting the final touches on what may be, in his own chosen conservative terms, his greatest foreign policy disgrace. He is preparing to hand Nicaragua's Sandinistas, whom he loathes with a passion, an indescribably sweet victory that they will be tempted to hail as a historic triumph of revolution over imperialism and that will leave him as the president who ''lost Nicaragua.'' If Daniel Ortega had any sense of irony, he would be planning to erect a statue of Ronald Reagan inscribed ''To Our Favorite Yankee, Who Made the Revolution Secure.''

Why the tribute? Because, inheriting a Sandinista regime that held but had not consolidated power, Reagan mustered the sort of resistance that was not enough to oust the regime but was enough to help it reach out from its narrow ideological base and to organize itself successfully around a broad, patriotic theme.

Because he will be leaving Nicaragua in a substantially improved international position -- with the support of the usual friends of Third World revolution plus the sympathy of most American allies. On no single issue is the United States more isolated.

Because having failed to dislodge or tame the Sandinistas, Reagan further failed to exploit the best alternative: weaving them into an international web in which they would have to accept obligations -- obligations flowing to many others besides the United States -- to move toward pluralism, to temper the revolution's totalitarian streak and to loosen its Cuban-Soviet connection.

This last failing comes into stark view now as a result of the fading out of the peace plan offered by Costa Rican President Oscar Arias Sanchez. Reagan found the plan lacking, since it does not nail down a full Sandinista passage to democracy as the price Nicaragua would have to pay for being relieved of an American-sponsored war. Equating such a passage with defeat, Ortega refuses to pay.

The plan is lacking. Arias himself accepts the idea that, once the pressure of the contras had been removed by his plan, the Sandinistas might prefer to face exposure as cheaters rather than the real political opposition that compliance with the plan would bring.

But the plan was also the last best hope to avert the worse outcome of a humiliating legislated end to contra aid and a conclusion by the Sandinistas that they owe nothing to anybody and are free to impose whatever political pattern they choose.

The Arias alternative could have at least allowed and obliged Nicaragua's ambivalent fellow Latins -- all with a direct national interest in its observance -- to oversee Sandinista delivery on political assurances made to them in the treaty process.

The faltering of the Arias plan is not Reagan's fault alone. Nicaragua shares blame: even as it gave general approval, it refused to countenance discussion of its own internal democratization, and threw sand in everyone's eyes.

But fault-fixing is secondary. That the Managua Marxists resisted the political guts of the plan tells precisely and dramatically why Reagan was blind not to embrace it. Reagan thought the plan was flabby. Ortega found it threatening. Ortega, who was ready to take his chances on a continuing war, shrank from Arias' peace. Ever solicitous, Reagan provided the cover behind which Ortega then could hide.

Nicaragua is the premier place for working out the ''Reagan Doctrine'' of support for anticommunist insurgencies. We are learning what the Reagan Doctrine can mean: the triumph of the idea of insurgency over the idea of anticommunism. Insurgency as a means of carrying anticommunism in Nicaragua is turning out to be ineffective and counterproductive. A serious anticommunist administration would have turned long ago to negotiation as a more promising instrument. But the Reagan administration, profoundly frivolous, has not seen what is required to save what still can be salvaged of the president's original and valid purpose.

Does the president not have one close adviser able to go to him and say: ''Sir, you cannot get from here to there by your current route. Conceivably, you still could get partway there by another route''? Fantasy? If something like this doesn't happen, then prepare in your imagination for Managua's unveiling of a statute to Comandante Reagan, ''Who Made the Revolution Secure.''