Back pain, cramps and spotting- miscarriage?

I'm 4-5 weeks pregnant and I've been spotting for more than a week. It has been mostly light and dark brown blood, but it was bright red a couple of times. 
When the blood was red it was accompanied by really strong cramps and intense lower back pain. But after a while it stopped... And it was back to brown spotting.
I don't get it. I think I'm having a miscarriage but then it stops. What's going on?? 
UPDATE: I got an ultrasound done and they  couldn't find the baby in the uterus.... It's likely to be an ectopic pregnancy.