How to change AUTO mode to ALT_HOLD mode

I write a code which can be avoid obstacle. so when detect the obstacle in AUTO mode then need to go ALT_HOLD mode. copter going well ALT_HOLD mode from AUTO but can not stay ALT_HOLD position (going down)