One of the first steps to learning a pistol squat is being able to squat comfortably on both legs.
If you can't do a deep squat and get your bum to your heels while using both legs, you don't have much chance of learning to do it with one leg.
Another important element of the pistol squat is developing hip flexor strength. This is what will allow your to keep your lifted leg straight and lifted. You'll also need enough hamstring flexibility that you can sit with knees straight with your torso at least slightly tilted forwards.
One of the critical positions of the pistol squat is squatting so that the hip is at knee height. This is the point at which your knee is perhaps under the most stress since the thigh is horizontal. When squatting on both legs to this position practice stabilizing either your heels or your forefeet. Use whichever makes your knees feel most comfortable.
The other critical position is the bottom position. While eventually you may want ot to try and relax in this position, first work at keeping your feet and hips active in this bottom position. Here again your knees will be under potentially a lot of stress since they are full closed and bearing the weight of your body. If either of your knees are uncomfortable in this bottom position, work on foot and hip activation and positioning so that your knees are comfortable.
Some basic pistol squat preparation exercises you can do on both feet include lowering from standing to the thighs horizontal postion, pausing then standing up. Then starting from a deep squat, lifting to the thighs horizontal position, pausing and then lowering back down again.
Because the pistol squat is a single legged squat you can practice shifting your weight gradually to one leg in both of the previous positions. These exercises should be done smoothly and with control so that any point that a knee, foot or hip feels uncomfortable you can stop before injury occurs.
In the thighs level squat, you can brace your right hip and foot then shift your weight to your right foot. Go slowly and notice your left leg relaxing. If it relaxes completely that means your weight is on your right foot and you can try lifting your left foot a few inches. Here again, work at a slow and smooth lift. If you can't do that, you need to better brace your foot and hip, or you haven't got your weight fully onto your right foot.
You can also practice this exercise in the bottom squat position.
In a deep squat, if you can get all of your weight onto one leg, then gradually reach the other leg forwards.
Don't worry about trying to stand just yet. Instead, see if you can reach your leg forwards, pause, then bring it back. Then switch legs. If you can't get your foot all the way forwards, go as far as you can.
If you find your thigh cramps, try rotating the leg inwards or outwards slightly or moving it inwards or outwards slightly.
Next you can practice the same thing but from the middle position. Shift weight to one foot, then lift the other foot and reach it forwards.
Once you are comfortable with these two positions you can work at standing up from the bottom position.
Rather than trying to lower into a pistol squat just try standing up in it. Then squat back down using both legs.
Once you are proficient with standing up from a pistol squat, then work at lowering.
Before lowering into the pistol squat makes sure that your foot and hip are braced. And work at lowering slowly and in control so that you can stop at any point. This is important so that if you get any sort of knee pain you can stop your self before it becomes a problem.