Shares were buoyed by the energy sector as oil prices recovered from falls.
The Dow Jones rose 75.9 points, or 0.42%, to 18,053.58, while the S&P 500 gained 9.35 points, or 0.45%, to 2,108.95. The Nasdaq added 33.38 points - 0.66% - to 5,104.89.
The rise was despite Commerce Department data showing that US retail sales fell 0.3% in June.
Analysts had not been expecting retail sales to fall, and the figures were the weakest reading since February.
Core sales - which exclude cars, petrol, building materials and food services - also fell, dipping by 0.1%.
Shares in JP Morgan Chase rose 1.4% after the bank reported a 5.2% rise in second-quarter earnings to $6.3bn.
Wells Fargo also rose by 0.9% after it reported second quarter earnings of $5.7bn, unchanged from a year earlier.
News of a nuclear deal between the US and Iran lifted oil prices. The S&P energy sector advanced 0.8%, led by a 0.84% gain in Exxon Mobil.
Gains were broad, with nine of the 10 major S&P 500 sectors ending higher, led by a 1% gain in the healthcare index.
(Close): US markets closed up for a fourth straight session, the longest winning streak since January.