I experienced a similar problem, with flashing vertical lines of various colours on my iMac 2011. Contrary to common belief, it was not a hardware issue!!
I took these steps which eventually solved the problem :
Apple Hardware Test (reboot, then press and hold down the "D" key until it boots):
No problems to report.
Permanently deleted everything and did a fresh OS install:
Ran well for about 6 months until the lines started to come back anyways (Now you don't have to try this! Lol)
Apple Hardware Test and the Extended Hardware Test (reboot, when you hear the apple chime immediately press and hold down the "D" key)
No problems to report.
Upon reaching the conclusion of my efforts, I decided that this ongoing problem could be due to conflicting software I had installed (again..... sigh....) at some points.
Before removing third party software, (or any software for that matter) back up ALL of your important data in a different location!!
Boot into Safe-Mode, and look for any third party software. Especially if you do not need it. If it is not made by Apple, it may be causing this problem.
Every computer's configuration is different then anothers. So do a bit of digging around, find any after market third party software, applications (especially those which run in the background all the time. Yuck!), plugins, sound drivers, video drivers etc.
(Tip: Do not use system cleansers, Mac 'cleaners' or file scanners. They can make your computer run worse!!)
Basically, if its not Apple, chuck it out. If you change your mind later, you could reinstall from the backup you have made.
For me, my problem was "Mac Fuse" software, which I located in my System Preferences list. Check there first, as it is a common place for third party dwellers to embed themselves. Then, check your Applications list and browser plugins/extensions.
To remove third party software ALWAYS look to each different publisher for instruction on how to do this properly. They are responsible to help you with that, if you should need it.
Once I properly removed Mac Fuse, I rebooted my computer into normal mode and Viola!!! My machine runs as it should again!!!
Hope this helps, thanks for reading.
Note: Three years ago I upgraded my ram to full capacity and am running Mac OS High Sierra. Runs well.