If you have gold out, they can attack you. If you have no gold out, they can't attack you. If your stats are too high and you arn't at war with them they can't hit you. If your stats are too low and you arn't at war they can't hit you. If you have a troop building up you can be hit at 0 gold but they can't hit you if you are at low troops aka 'pinned'.