OK, let's go through the logic of this:
To leave a moon and return, presumably, to a low orbit around the parent body, you can think of the process as being in two steps: Step 1 is leaving the moon with the right velocity and direction to get away from the moon and to leave you in position for Step 2. Step 2 is just the gravitational fall along a predominantly elliptical trajectory from the orbital radius of the moon back down to low orbit around the planetary body. To do Step 1, you first need to work out Step 2. So we'll focus on Step 2 first.
We can imagine that at the start of Step 2 (i.e., just after Step 1 where you have left the moon) you are at the apoapsis of an elliptical orbit around the parent body where the elliptical orbit takes you all the way back to the parent body such that when you arrive at periapsis you are at your target altitude for orbital insert. AT&T point, a retrograde burn inserts you into a circular orbit.
Assuming this, what do we know?
At the start, and with respect to the parent body, you are at a distance [MATH]r_m[/MATH] from the centre of the parent body, where [MATH]r_m[/MATH] is the orbital radius of the moon. (To keep things simple, we'll assume that the moon is in a near circular orbit around the parent body.)
Let's call [MATH]r_p[/MATH] your target altitude at the parent body when you reach periapsis there. Presumably, you know this. Most likely, in the case of the Earth, say, you want to be a few hundred kilometres above the surface so that [MATH]r_p[/MATH] would be somewhere around 6,570 km.
Now, I'm not going to prove this here but from these two pieces of information, we can work out the speed you need to have at the start of Step 2. Let's call this [MATH]v_a[/MATH] - your speed at apoapsis:
[MATH]v_a = \sqrt{\frac{2\,\mu \, r_p}{r_m \left(r_m+r_p\right)}}[/MATH]
where [MATH]\mu[/MATH] is the standard gravitational parameter for the parent body. A list of standard gravitation parameters for Solar System bodies can be found here:
https://en.wikipedia.org/wiki/Standard_gravitational_parameter.
Note that the units of these standard gravitational parameters is 'km' and 'seconds'. This means that to be consistent you have to do all your calculations in 'km' and 'seconds'. So, that [MATH]v_a[/MATH] above would be expressed in 'km/s'.
So that's it for Step 2. We know that when we are done with Step 1, we need to be at apoapsis of an elliptical orbit with a speed of [MATH]v_a[/MATH]. Gravity will then do the rest and take you back to your target periapsis altitude at the parent body.
OK, but how do we match with this with Step 1?
Well, let's calculate the speed with which we have to leave the moon in order to get to our starting position for Step 2. If it is in a circular orbit, the moon is orbiting the parent body at a speed [MATH]v_m[/MATH] where
[MATH]v_m = \sqrt{\frac{\mu}{r_m}}[/MATH]
To get to the start of Step 2, then, and when we are sufficiently far away from the moon that its gravity no longer has much impact, we need to find ourselves moving away from the moon with a speed that is the difference of [MATH]v_m[/MATH] and [MATH]v_a[/MATH]. This difference is typically called the 'hyperbolic excess velocity' and labelled [MATH]v_\infty[/MATH]. In other words:
[MATH]v_\infty = \sqrt{\frac{\mu}{r_m}} - \sqrt{\frac{2\,\mu \, r_p}{r_m \left(r_m+r_p\right)}}[/MATH]
This is the speed (relative) to the moon that you need to have - once you have completed your prograde burn around the moon; and have moved far enough away from the moon that its gravity is no longer significant.
Now, we get down to the timing and magnitude of the prograde burn needed to do this. Here, to keep the maths simple, I'm going to assume that you start off in orbit around the moon that is 'in plane' with the orbital plane of the moon around the parent body. If you are not 'in plane' then you will find yourself being thrown away from the moon at an angle after your prograde burn and working out how to compensate for that angular throw involves significantly more maths. But if you are 'in plane' with the orbit of the moon around the parent body (Align Plane MFD helps here) life (and the maths) is much, much simpler.
When you execute a burn that takes you above 'escape velocity' two things will happen, you will rotate around the planet by a certain angle, [MATH]\theta[/MATH]; and you will leave the planet with a certain hyperbolic excess velocity [MATH]v_\infty[/MATH]. If we know your initial orbital radius around the moon (which I will call [MATH]\rho[/MATH]), then you can connect all three of these things together. And since, you know two of them [MATH]\rho[/MATH] and [MATH]v_\infty[/MATH], you can work out the third, [MATH]\theta[/MATH].
The equation that connects these three quantities is:
[MATH]\theta = \sin ^{-1}\left(\frac{\mu _m}{\mu _m+\rho \,v_{\infty }^2}\right)[/MATH]
where [MATH]\mu_m[/MATH] is now the standard gravitational parameter for the moon (and not the parent body).
Note, too, that the [MATH]\sin ^{-1}[/MATH] normally returns an angle measured in radians and not degrees. To convert to degrees one has to multiply the angle measured in radians by [MATH]180/\pi[/MATH] to convert to degrees.
Let's just take a quick look at this function: if you want to leave the moon very quickly, with a very high [MATH]v_\infty[/MATH], your angle of rotation around the moon as you complete your hyperbolic escape will be very low.
On the other hand if I want to 'only just' escape the moon (such that [MATH]n_\infty[/MATH] is close to zero, then after you complete your prograde 'escape' burn, you will continue to rotate around the moon by a further 90 degrees. In this case, if you want to leave the moon so that you end up heading away from the moon backwards along the orbital path of the moon around the parent body, you will need to execute the escape burn at a point in your orbit when you are pointing inwards towards the parent body, the hyperbolic escape will then continue to rotate your velocity vector around another 90 degrees so that by the time you have escaped, your velocity vector is pointed in the direction you want it - namely directly away from the moon along its orbital path around the parent body. This is the origin of the idea that you wait for the parent body to appear above the horizon before you begin your escape burn.
But let's be a little more precise here. We have enough information to calculate the angle [MATH\theta[/MATH] that your velocity vector will be rotated by as you complete your hyperbolic escape. This angle will be somewhere between 0 and 90 degrees. Typically, it will be closer to 90 degrees than 0 degrees. Let's suppose that you calculate [MATH]\theta[/MATH] to be 75 degrees. Then, you will need to wait until the planet is 15 degrees above the horizon before beginning your escape burn.
But how big should my burn be? Well, the quantity
[MATH]\frac{\mu _m}{\mu _m+\rho \,v_{\infty }^2}[/MATH]is just the inverse of the eccentricity that you need to reach. So, you know when to shut off your engines when your orbital eccentricity (referencing the moon) equals:
[MATH]e = 1 +\frac{\rho\, v_\infty^2}{\mu_m}[/MATH]
So, in all this should be enough to work out (broadly) when to start your engines and when to stop your engines.
Of course, all of this maths is a bit approximate. Don't expect 'pin-point' precision if you do this. But overall, it should work tolerably well.