Gradient-based optimal control of open quantum systems using quantum trajectories and automatic differentiation