This is a question best asked of your personal physician so you can get advice that is specific for you. If you have symptoms during sexual activity, talk to your doctor.
In general, the American Heart Association says that people who are able to do moderate-intensity physical activity (such as walking 3 miles per hour, bowling, dancing, golfing, and hunting) without symptoms are at very low risk of a heart attack during or immediately after sexual activity.
If you’ve had a recent heart attack or heart surgery, start slowly with activities that are less strenuous than sexual intercourse, such as kissing, hugging, fondling, mutual masturbation, and oral sex. If you have no chest pain, shortness of breath, rapid or irregular heart beat, or dizziness during or after these activities or fatigue the next day, then it’s probably okay to engage in intercourse. If you are unsure, check with your doctor.
People who have mild, stable chest pain are at low risk for heart events triggered by sex. Being physically active will help lower your risk even more. On the other hand, people who have unstable angina or chest pain that is difficult to treat are at high risk and should not engage in sex until their condition is stable and they get the okay from their doctor.
If you’re having trouble resuming sexual activity, see your doctor. Difficulties are commonly caused by medications, depression or anxiety, and fear of causing a heart attack. Many of these issues can be successfully addressed with help from your physician or a sexuality counselor.
(Source: Steinke EE, et al. Sexual counseling for individuals with cardiovascular disease and their partners: A consensus document from the American Heart Association and the ESC Council on Cardiovascular Nursing and Allied Professions [CCNAP]. Circulation. 2013;128:2075-2096. http://circ.ahajournals.org/content/128/18/2075.full?sid=83bbdd71-c73b-4664-b366-fd8fbb294dbe)