It seems that you are having some ligament or cartilage injury
giving rise to this problem.
If you are elderly then there is a chance of having osteoartheritis of knee joint.
Go for x-ray knee and confirm the ailment you have.
Go for Patellar exercise daily 10 minutes for 2-3times.
Do not sit on squatting position.
Do not have cross legs.
Ok and take care.