Has this made your computer unusable or will it start back up and only does this if you nudge it? Could be your PSU is going. How old is it? You could get a multimeter to test it, you just have to be careful to not electrocute yourself.
Here's a guide:
https://www.lifewire.com/how-to-manually-test-a-power-supply-with-a-multimeter-2626158
I'd also unplug it, open it up and check all the connections to make sure that nothing is loose. It's also a good idea to clean out any dust with some compressed air while it's open. I'm sure you know to wear a grounding cable while fiddling around inside but I figured I'd mention it anyway. With this only happening when you nudge it I think a loose connection is probably the most likely issue. It's also possible that your cable is going out or the port the cable is in is going. I had that happen to me when I got a new monitor and thought it was the cable but it turned out to be the port on the graphics card, luckily my card had another DP port. You could check those two things before you check all the inside connections.