I completely agree with what you write.
I think a part of the problem with this entire discussion is that people who talk about American "Greatness" define "Great" in their heads to mean "perfect" or "without any faults, past or present." A country can be simultaneously great, while still greatly flawed.
To draw the historical example: The Republic (and later the Empire) of Rome was a great nation at one point, both for its societal achievements, its development of the principles of rule of law, the ideas of the individual rights of citizens, and of course, its economic and military dominance of the ancient world. Many of its founding principles last to this day, most obviously the principle of the rule of law and individual liberties of citizens. However, no one would say that Rome was in any way perfect, because as anyone who has studied ancient history could tell you, while Roman philosophers were discussing matters of principle, the Romans had perfected the institution of slavery, committed massive campaigns of brutal conquest and subjugation of their neighbors and rivals, and mass-enslavement of conquered peoples, and in, some cases, their generals even bragged about mass-extermination of entire tribes who had defied them down to the last crying child. But these evils and flaws did not mean that Rome was not great.
In the same way, the United States was and is still great, and its sins are not nearly so egregious as that of the Romans. The United States and the principles under which it was united and founded have withstood the test of time. The principles of individual liberty, freedom of worship, freedom to own one's labor and property, freedom to engage in social and economic intercourse with whomever one so chooses, and above all tolerance enforced by rule of law, have made America rich both economically and in spirit. That is not to say horrible acts were not perpetrated along the way. No one can or should deny the evils of slavery. No one can or should deny the evils of the mass-relocation and genocide against indigenous tribes. But even during these most horrible times, America was still a great country. Not perfect, but great. And we have only gotten better over time.
Certainly, as the son of an immigrant who moved to this country from the horrible nation that is Iran, I can state without equivocation that America is a great country, both for the liberty afforded to her and her family, as well as any number of immigrants who are lucky enough to find refuge on her shores. America is a land of freedom and opportunity, and as long as it remains so, it shall remain great.