Balancing quadcopter using mpu6050
I suggest you to look at Automatics and PID regulation.
Your approach is not wrong, but you're missing a LOT.
For instance, how do you know but what amount you should change the speed of your motors to compensate the tilt angle ? How do you make it go to a stable position in a smooth motion ? How do you optimize the time to get to a stable position ?
All these questions can be answered by learning about automatics.



If you look at this scheme, consider the Setpoint as your reference-level and Output as your quad-level.
Setpoint - Output = Error (ie. the angle between your quad-level and the ref-level).


Now the P gain is going to multiply your error in order to send a correction-command proportional to the error.
The I gain is going to integrate the error. Integral are sums, this terms kicks in when the error is so small that the P gain can't really do anything about it.
The D gain will multiply the derivative of your error, it will basically smooth your output command (DO NOT confuse with Output, the quad-level)


By the way, when you say 'ax' do you mean the raw value you read on the 'x-axis' of your mpu6050 ? Because that's not your reference.

You should find most of your answers by looking at the multiwii code.