Does sex harm pregnancy?!!

I heard it doesn’t by my doctors even my sisters who have children that it doesn’t.

But for some reason when I had sex with my boyfriend whenever I was pregnant I lost my baby literally the next night.. happened twice.. idk if it’s just bad timing or what.. but it freaks me out and I don’t want to be distant with him now that i’m pregnant again but I also don’t want to be touched or have sex now until I know my baby is okay.