Nosebleeds induced by sexual arousal are a very popular trope in Animes, Mangas and Japanese medias in general. Although a widely spread notion, it is not backed by medical science.
The events in this episode directly follow on from the events in the previous episode, which is when Ted turned 30, but when Ted tells Marshall & Lily that he hasn't had sex in 2 months, Marshall states that Ted hasn't had sex since Thanksgiving. Ted's 30th birthday was April the 25th 2008, and Thanksgiving 2007 was November the 22nd, meaning Ted hasn't had sex in over 5 months. Ted does, however, later tell Stella that it's been 5 months.