The S&P 500 and the Nasdaq edged up to record closing highs for the third consecutive session as investors struggled over whether to take profits following a rally on positive developments in trade disputes which have vexed the markets.

Following a United States-Mexico agreement Monday to overhaul the North American Free Trade Agreement (NAFTA), focus shifted to Canada, with its top trade negotiator joining her Mexican and U.S. counterparts in Washington in a bid to remain in the trilateral pact.

The Dow Jones Industrial Average also closed marginally higher in a late summer, low-volume session of back-and-forth trading as investors debated whether to cash in or ride the market’s momentum.

Technology companies led the advance, offset by declines in energy, telecom and materials sectors.

Tiffany reported better-than-expected second-quarter results and raised its full-year profit forecast. The stock ended the trading day with a gain of 1.0 percent.

Sears Holding rose 12.6 percent as its Auto Center partnership with Amazon expanded, its services now available nationwide. The partnership was first announced in May.

Yum China rose 3.9 percent following a Wall Street Journal report that the fast food operator rejected a buyout.

Of the 11 major sectors of the S&P 500, four ended the session in positive territory, with real estate and technology posting the largest percentage gains.

Among losers, shares of Best Buy fell 5.0 percent after the electronics retailer reported a decline in online sales growth and provided underwhelming third-quarter profit guidance.

Campbell Soup closed 2.1 percent lower after a New York Post report that the company does not plan to sell itself.

Tesla extended its decline, falling 2.3 percent in the wake of Chief Executive Elon Musk’s decision to abandon his idea of taking the company private.

Finally, the S&P CoreLogic Case-Shiller composite index of 20 metropolitan areas rose 6.3 percent in June on a year-over-year basis after increasing 6.5 percent in May. House prices are being driven by tight inventories.

The combination of higher house prices and rising mortgage rates is making the purchase of a home unaffordable for some Americans, especially as wage growth lags. That has hurt home sales, leading to a slowdown in the housing market.

Approximately 5.58 billion shares changed hands on the major domestic equity exchanges, as compared to the 6.18 billion share average over the past 20 trading days.

Trade Deficit Rises

The Commerce Department reported on Tuesday that our trade deficit widened sharply in July as exports of agricultural products tumbled, suggesting trade will likely be a drag on economic growth in the third quarter.

According to the Department, the goods trade gap rose 6.3 percent to $72.2 billion last month. Exports of goods fell 1.7 percent to $140.0 billion, weighed down by a 6.7 percent decline in shipments of food, feeds and beverages.

That likely reflected a continued reversal of soybean exports after farmers front-loaded shipments of the crop in April and May to China before Beijing’s retaliatory tariffs came into effect in early July. The United States and China are embroiled in a trade war marked by tit-for-tat tariffs.

Last month, there were also decreases in exports of capital and consumer goods, though motor vehicle exports rose. Imports of goods increased 0.9 percent to $212.2 billion in July, aided by imports of food, industrial supplies and capital goods. There were also increases in motor vehicle imports, but imports of consumer goods fell.

For the second quarter, trade contributed 1.06 percentage points to the economy’s 4.1 percent annualized growth pace. Nonetheless, in spite of the anticipated drag from trade, economic growth in the July-September quarter is still likely to remain solid.

The Commerce Department also reported on Tuesday that wholesale inventories rose 0.7 percent in July and stocks at retailers increased 0.4 percent, suggesting inventories could provide could also add to gross domestic product this quarter.

There was an outright inventory liquidation in the second quarter. As a result, inventories subtracted a full percentage point from GDP growth in the April-June quarter.

Consumer Confidence at 18-Year High

Consumer confidence hit an 18-year high in August, as households remained upbeat on the labor market, pointing to strong consumer spending that should help to sustain the economy for the remainder of the year.

The rise in confidence this month suggests consumers are little worried about the Trump administration’s protectionist trade policy, which has led to an escalation of a trade war between the United States and China as well as tit-for-tat tariffs with the European Union, Canada and Mexico.

The duties on imports will raise prices for consumers as well as make raw materials more expensive for some manufacturers. There have been reports of some companies either laying off workers or planning to because of the import tariffs.

The Conference Board reported that its consumer confidence index rose 5.5 points to 133.4 this month, the highest reading since October 2000. Consumers’ assessment of both current business and labor market conditions improved further in August.

Many consumers said they planned to buy a house or another big-ticket item in the months ahead. The survey’s so-called labor market differential, derived from data about respondents who think jobs are hard to get and those who think jobs are plentiful, rose to 30.0 in August from 28.0 in the prior month.

The Conference Board survey’s findings are in stark contrast with a University of Michigan survey showing consumer sentiment falling to an 11-month low in early August as households worried about rising inflation eating into their modest wage increases and eroding their purchasing power.

The divergence between the two surveys is likely the result of their treatment of the labor market.