How to scale grades to take into account how strong the students are?
are you asking about just converting everything into standardized scores? 

In which case, you take the mean of relative performance (for example, if you are teaching a senior level course, you might take the major gpa distribution rather than overall gpa distribution) assign everyone a z-score based on their position in the calculated normal distribution.

you do the same for your test, standardize the score. For example, if your test average is a 50 with an SD of 10, a person who got a 70 has a z of 2 while a 45 has a z of -.5. 

Now if you are planning on basing their recorded grade based on expected performance you are probably opening up a serious can of worms.  For example,  a student who consistently scores in the z score range of 1.8-2.1 and then only scores at a 1.5 is given an 75 (assuming mean 80 score, and 10 sd) while a student who consistently scores at a -.5 to -.8 range and scores a zero is given an 85 on the test.

If this is your plan, I would seriously rethink it. Not only will it upset students, it penalizes high performing students and rewards low performers.