An optimization method for a radiotherapy plan using robust optimization to handle different scenarios that may occur during one treatment session because of patient movement. The optimization is based on the period and amplitude of the movement, the starting point of the treatment session within a period and the delivery time structure.