President Reagan wrote a few lines of his own today into a script that called for him to campaign at arms' length from maverick Rep. Millicent Fenwick, the independent-minded New Jersey Republican Senate candidate.

The script called for Reagan to help Fenwick remedy a serious fund-raising problem, but not to embrace her too tightly in a state with 9.2 percent unemployment and a Democratic Senate candidate who is running against the president's economic policies.

But Reagan didn't stay at arms' length. He gracefully walked with Fenwick down the steps of Air Force One, and, arm in arm, escorted her into a $500-a-person fund-raiser in rural Whitehouse, N.J.

"Millicent and I stand shoulder to shoulder" on the important issues, Reagan told the 200 Republicans who crowded under a big green and white tent.

Fenwick's campaign had closed the event to press coverage, but reporters nearby overheard Reagan's 20-minute question-and-answer session in which he displayed a fondness for Fenwick, the model for character Lacey Davenport in Gary Trudeau's comic strip Doonesbury.

"Millicent and I don't always agree on all things, but I know when we do disagree, I know we can sit down together and she's even suggested we can smoke the pipe of peace," Reagan said.

Of the New Jersey Senate candidates, only Fenwick has "the character, independence, wisdom and legislative experience needed to help create real jobs without inflation and work for peace through strength," he added.

The matter of Reagan's identification with the aristocratic and sharp-witted Fenwick is important to her campaign because she is strapped for money while Democrat Frank Lautenberg is spending several million dollars to link her to Reagan's troubled economic policies.

Fenwick voted for Reagan's tax-cut and budget bills in 1981, but has kept her distance from his economic policies in 1982, saying "I pray it works," hardly a ringing endorsement. Today at the San Gennaro Festival here she acknowledged: "The president and I are not always in perfect accord."

Reagan has not always campaigned with gusto for those who oppose him, as was the case in the lackluster appearance he made a few weeks ago for San Diego Mayor Pete Wilson, the California GOP Senate nominee.

But it was clear today that Reagan, 71, and Fenwick, 72, share a mutual admiration that overshadows their sometimes considerable political differences. As politicians they both ran for office after first establishing themselves in other careers and both have personalities that often seem larger than their politics.

As they left the Ryland Inn in Whitehouse today one onlooker held up a placard: "Your Tax Dollars at Work--71-Year-Old Actor Lunches With 72-Year-Old Comic Strip Character."

At a time when Democrats are portraying Reagan as a rich man's president who is out of touch, Fenwick affectionately called him a "great and loving president, someone who cares about us."

The main mission of the president's five-hour foray into New Jersey, the first time he has campaigned in a northeastern industrial state this fall, was to sidestep differences and help raise money for Fenwick, who throughout her career has forsworn contributions from corporate political action committees.

Reagan raised $100,000 for her. Conspicuously absent, however, was New Jersey resident and Labor Secretary Raymond J. Donovan, a prominent fund-raiser for Reagan in 1980 but now a potential political liability in his own state. White House officials said Donovan had "a previous commitment" in Georgia today.

New Jersey has long been a Democratic state but it provided the sixth-largest majority for Reagan in 1980. Polls show that while he isn't as strong here today as he was two years ago, Reagan is not a negative factor for Republican candidates.

As Fenwick and her advisers hoped, the president came to lend his powerful personal appeal to her fund-raiser but he stayed away from controversial issues. He made only passing reference to the economy and said nothing about the conservative social issues of abortion, school prayer and tuition tax credits that he has been pushing in Washington recently.