This has always been a common misunderstanding. To be clear, while the FICO scoring formula considers the number of accounts on file and the mix of different types of accounts, it does not specifically look at the number of open vs. closed accounts.
In fact, FICO scores and the myFICO site have never actually had any negative factors or
explanations that refer to "open" accounts as having a negative effect, but people seem
have taken "number of accounts" to automatically mean "number of open accounts".
Also, the only area of scoring where closing an account can hurt you is in the revolving utilization calculations. While a closed revolving account with a balance is included in utilization, a closed account with a zero balance is not.
In the area of length of credit history, closed accounts are treated no differently than open accounts.
That is, the length of history on a closed acct still gets counted right along with the rest of the closed account's history. In fact, the length of credit history gets counted for every trade line on your report, regardless. So, the only harm by closing a revolving account is to the utilization percentage, while,
in the long run, a closed account will be removed from your credit file after 10 years, which could lower your score at that time due to the loss of that history.