Stocks closed mostly flat on Tuesday after volatility late in the session, with weakness in materials and energy shares offsetting strength in financials.