US stocks close with gains amid hopes for Iran ceasefire