Praise be to Allah.
If what you did was something usual and there was no fear for the foetus, then you do not have to do anything, because the basic principle is that it is permissible for you to do these things.
But if the action was something that is usually known to be harmful to the foetus, such as carrying heavy things, for example, which a pregnant woman is not supposed to carry, and that resulted in miscarriage of the foetus – in the fourth month, as mentioned in the question – then the miscarriage of the foetus is not regarded as killing a person, because the soul had not yet been breathed into it, as the soul is breathed into it after one hundred and twenty days of pregnancy.
Based on this, there is no diyah (blood money) or kafaarah (expiation) required as the result of this miscarriage.
Rather this miscarriage incurs a burden of sin, and you have to repent and regret what you did.
The scholars of the Standing Committee for Issuing Fatwas were asked : I went for Hajj with my husband and some of my children, and I was four months pregnant. On the night of ‘Arafah we carried our luggage and because we had so many things and they were heavy, I felt pain in my stomach. On the same night I lost the foetus, and I buried it without washing it or offering the funeral prayer for it. I was at the end of the fourth month, and I had had some bleeding during the month of Dhu’l-Qa’dah. After the miscarriage I had bleeding of nifaas, which lasted until the end of Hajj. My question is: Do I have to do anything because of having a miscarriage during this period? Please note that I did not wash him or offer the funeral prayer for him, and I did not tell anyone about that, and the miscarriage was not something that I wanted.
They replied: If the matter is as you describe, that the pregnancy was in its fourth month and had not yet completed four months, then you do not have to offer any expiation for the miscarriage of this foetus, because the soul had not yet been breathed into it during this period. Based on that, the foetus does not need to be given a name, washed or prayed for, but you were sinning because you caused this miscarriage, so you have to repent and pray for forgiveness for what happened, and not do such a thing again in the future. End quote.
Fataawa al-Lajnah al-Daa’imah (21/339).
If a woman starts to fast for two consecutive months then her period comes, she should stop fasting during her period, then complete the two-month fast after her period ends.
Ibn Qudaamah (may Allaah have mercy on him) said: The scholars are unanimously agreed that if a woman who is fasting for two consecutive months gets her menses before she completes the fast, she should make it up when she becomes pure (i.e., her menses ends) and she should continue from where she was before her menses came. End quote from al-Mughni (8/21).
And Allaah knows best.