Traders work on the floor of the New York Stock Exchange on June 22. (Michael Nagle/Bloomberg)

The calm predictability that was the signature of the 2017 stock market has been replaced by the turbulence of the first half of 2018, with investors frazzled by the drum of trade threats between the United States and China.

The once-preening Dow Jones industrial average has erased all of its 2018 gains and is bobbing close to 10 percent correction territory, compared with its Jan. 26 high.

Some would see the pullback as a buying opportunity, especially given that the economy is otherwise robust. The gross domestic product is cresting at $20 trillion any day. What’s an investor to do? Stay the course. Stick to your plan. Look long term.

But the “headline risk” of presidential tweets, White House pronouncements and breathless policy leaks made for a pretty rocky second quarter. If not for the tariff talk, Steve Forbes said on Fox Business “Mornings with Maria” a few days ago, the Dow would probably leap thousands of points.

The major indexes rallied Friday and notched slight gains as the quarter closed. The blue-chip Dow rebounded toward the end of a turbulent week, up 55 points at Friday’s close.

The Standard & Poor’s 500-stock index and tech-heavy Nasdaq composite index were positive in Friday trading, with the Nasdaq finishing up more than 6 percent for the second quarter.

Most market watchers place blame for the bumpiness squarely on President Trump, who ups the ante on tariff threats almost daily.

“It’s all him,” said Ed Yardeni of Yardeni Research. “His tax cuts boosted earnings dramatically. But, on the other hand, his protectionism is a possible threat to the economy.”

Despite relatively blue skies, there’s plenty of other economic threats feeding into investors’ existing anxieties. Layered on top of the trade talk are the price of oil at multiyear highs, a strengthening U.S. dollar, the Federal Reserve foreshadowing interest rate increases, and Europe’s economies slowing.

Even the halo over technology shares was shaky the last week of June, with the Nasdaq working through one of its worst weeks of the quarter. Throw in a national donnybrook expected over an empty Supreme Court seat, as well as a looming midterm election, and you have a nervous “investorate.”

Wednesday’s markets are a case in point. The Dow swung 441 points on mixed messages bouncing out of the White House.

Trump’s trade adviser Peter Navarro told CNBC on Monday that “there’s no plans to impose investment restrictions on any countries that are interfering in any way with our country.” Treasury Secretary Steven Mnuchin followed with a statement that the administration would seek legislative redress through the Committee on Foreign Investment in the United States, instead of more direct methods to curtail theft of vital U.S. technology by rival countries (Pssst. We mean China.)

“If there are mixed messages, again, that’s something that’s unfortunate,” Mnuchin said on CNBC, responding to a question about inconsistencies from co-anchor Andrew Ross Sorkin. The Dow at first responded favorably to Mnuchin’s comments, running 285 points upward.

But by day’s end, the benchmark had given all that up and more, to close 165 points in the red.

“I don’t think anybody knows how serious the president is or isn’t about trade,” said Michael Farr, a Washington investment manager. “I heard someone say, ‘Most people pause when they shoot themselves in the foot. The president wants to reload.’ ”

The S&P 500 is staying above water at  about 2 percent year to date as of Friday but was down about 5 percent off the Jan. 26 high. The hardest-hit sectors have been the industrials and materials sectors, which stand to lose the most in a tariff war. Industrials were down 3.6 percent in June and down more than 5.8 percent on the year as of Thursday’s close.

The Chinese are feeling the pain, too. The benchmark Shanghai composite index fell 0.9 percent to 2,786.90 on Thursday, its lowest finish in more than two years.

The president has money in the bank to play with if he wants to keep poking the Chinese on trade. The S&P 500 is up 26.96 percent since his election Nov. 8, 2016. That number grows to 31.18 percent if you include stock dividends.

Analysts say the president cares too much about the stock market to blow it, especially with the crucial midterm elections four months off.

“There is a limit to how far the president may take the trade battle if stocks fall enough,” John Lynch, chief investment strategist for LPL Financial, said in a recent report titled “Trade Tensions Playbook.”

“President Trump has a track record of starting a negotiation from an extreme position and then moving toward compromise. We expect resolution with China on trade, and only minimal economic damage to the U.S. and abroad,” Lynch said.

Howard Silverblatt, a senior index analyst with S&P Dow Jones Indices, suggests market wags stop trying to read the tea leaves and wait for whatever action Trump takes.

“The difference is rhetoric versus what I am actually doing,” Silverblatt said. “Pay no attention to the man behind the curtain,” he said in a nod to “The Wizard of Oz.”

Tariff talk has been brewing for months, but the threats elevated after Trump left the Group of Seven summit in Quebec in early June. He left Canada refusing to sign a joint communique and then followed up by referring to Canadian Prime Minister Justin Trudeau as “very dishonest & weak.”

On June 14, Trump broadened the trade dispute with an announcement that he would impose a 25 percent tariff on $50 billion of Chinese products. China responded in kind, and the market slid lower.

Trump then upped the ante with a $200 billion salvo lobbed toward China, which was followed by retaliatory tariffs from India, a profit warning from a European automaker blaming tariffs, and Trump’s call for a 20 percent tariff on automobile imports from the European Union.

Then came reports that Trump wants to ban Chinese investment in U.S. technology as a way to protect our advances. Yet another report surfaced Friday on Axios that Trump wants to pull out of the World Trade Organization, which could send global trade into a spin. Mnuchin called the report “an exaggeration.”

Investors reacted, even as Trump’s economic team scrambled to calm fears.

“As much as the government wants to tell you we are having a trade dispute, Wall Street is saying we are having a trade war,” Farr said.

The technology sector, whose FAANG — Facebook, Amazon.com, Apple, Netflix, Google-parent Alphabet — stalwarts have carried much of the bull market in recent months, showed its vulnerability, even though it is up more than 500 percent since the bear market low of March 9, 2009. (Amazon CEO Jeffrey P. Bezos owns The Washington Post.)

The chatter during the week was that the turbulence and selling are because of a confluence of factors, including investors taking quarterly profits and typical seasonal weakness as the summer kicks off.

“While President Trump’s continued dialogue on tariffs seem to be leading stocks down, investors shouldn’t be too surprised that markets are experiencing weakness, given seasonal considerations,” said Wayne Wicker, chief investment officer at ICMA Retirement. “This is an election year, which typically provides additional challenges for markets. Historically, the fourth quarter provides a bit of a relief rally, which investors might keep in mind.”

Jamie Cox of Harris Financial Group said markets have been selling off because some companies have been warning that tariffs are going to hurt quarterly earnings, due in July.

“If earnings are going to be less than what people expect them to be, stocks are going to have to re-price,” Cox said.

That means things might get worse before they get better. Whatever happens, expect more volatility.

“If he had just given us the tax cut and watched Fox News until the midterm elections,” Yardeni said, “the market would be a heck of a lot higher today.”