DR4B Calculations

Does anybody have a formula that allows you to calculate the optimum gear ratio for a DR4B?

while TR<ST(GR=GR+1)
while TR>=ST(GR=GR-1)

where tr=torque required
st=stall torque of the motor
gr=gear ratio