After miscarriage

How long after miscarriage can you have sex ? And how long do I have to wait to get pregnant?