We need the past perfect continuous to describe the same situations as we do with the present perfect continuous, but the past perfect continuous indicates that we are speaking about the past.
Compare these examples
The grass is wet. It has been raining. → The grass was wet. It had been raining.
Mike is tired. He has been carrying heavy boxes all day long. → Mike was tired. He had been carrying heavy boxes all day long.
I am very happy to get this job. I've been waiting for this chance for several years. → I was very happy to get that job. I'd been waiting for that chance for several years.
Maria hasn't been learning English for a long time, but she speaks it very well. → Maria hadn't been learning English for a long time, but she spoke it very well.
So, we use the past perfect continuous in two cases that are very much alike:
- The activity started in the past, went on for some time and has recently or just stopped — recently or just in relation to the moment of speaking in the past.
Yesterday I had a problem with my task. It was difficult to find the answer. I had been browsing websites for an hour when I finally found a solution.
Nancy got a job last week. She had been looking for a job for the last two month.
- The activity started in the past, went on for some time. At some moment in the past, we stated that the activity had been going on for a certain period of time. Then the activity continued.
At eleven o'clock we noticed that we had been playing that game for five hours. But we didn't stop and continued playing.
It had been raining since Monday. Then it was Thursday and it seemed like the rain wasn't going to stop.
We don't normally use a continuous tense with stative verbs, like be, know, like, want, suppose, agree etc.
I had known Angela for years when we became business partners. (WRONG I had been knowing)
Bella had been pregnant for two months when she told her parents about the child. (WRONG had been being pregnant)
The signal words for and since will help you choose between the past continuous and the past perfect continuous. If we have "for" or "since" in the sentence, it is almost always a directive to use a perfect tense.
When I came home yesterday, the children were watching TV. It was late and they had been watching TV for too long, so I told them to go to bed at once.
Peter hadn't been feeling well since Monday. So, on Wednesday he finally went to see the doctor. He was still feeling bad when he came to the doctor.