LED retrofit lamp, adapted for operation with an alternating current and with a reactive lamp ballast (26, 26', 26"), comprising at least - a LED unit (7,7', 7", 7"'), - a compensation circuit with a controllable switching device (9, 9'), connected parallel to said LED unit (7, 7', 7", 7"') to provide an alternative current path, and - a control unit (10, 10', 10"), adapted to control said switching device in a compensation mode, in which mode said switching device is set to a conducting state for the duration of a shunt period in each half cycle of said alternating current during a reactive phase of said alternating current, and configured to adapt the power consumption of the LED unit (7, 7', 7", 7"') to a predefined compensation value, the control unit comprising feedback circuitry to measure a current and/or voltage of said LED lamp and adapted to control the duration of said shunt period according to said measured current and/or voltage; characterized in that, the control unit (10, 10', 10") is further adapted to operate in a first detection mode, in which mode - the switching device (9, 9") is operated with a first set of timing control parameters, so that a shunt end time of said shunt period corresponds to a zero-crossing of said alternating current, - the current of said LED unit (7,7', 7", 7"') is determined, - the switching device (9, 9') is operated with at least a second set of timing control parameters, so that said shunt end time does not correspond to a zero-crossing of said alternating current, - the current of said LED unit (7,7', 7", 7"') is determined again and - in case the determined current according to said first set is less than the determined current according to said second set, the switching device (9, 9') is operated with said first set of timing control parameters instead of continuing operation with the second set of timing control parameters. - a LED unit (7,7', 7", 7"'), - a compensation circuit with a controllable switching device (9, 9'), connected parallel to said LED unit (7, 7', 7", 7"') to provide an alternative current path, and - a control unit (10, 10', 10"), adapted to control said switching device in a compensation mode, in which mode said switching device is set to a conducting state for the duration of a shunt period in each half cycle of said alternating current during a reactive phase of said alternating current, and configured to adapt the power consumption of the LED unit (7, 7', 7", 7"') to a predefined compensation value, the control unit comprising feedback circuitry to measure a current and/or voltage of said LED lamp and adapted to control the duration of said shunt period according to said measured current and/or voltage; - the switching device (9, 9") is operated with a first set of timing control parameters, so that a shunt end time of said shunt period corresponds to a zero-crossing of said alternating current, - the current of said LED unit (7,7', 7", 7"') is determined, - the switching device (9, 9') is operated with at least a second set of timing control parameters, so that said shunt end time does not correspond to a zero-crossing of said alternating current, - the current of said LED unit (7,7', 7", 7"') is determined again and - in case the determined current according to said first set is less than the determined current according to said second set, the switching device (9, 9') is operated with said first set of timing control parameters instead of continuing operation with the second set of timing control parameters.