Is there a way to loop out a section of a layer, with the option to pingpong or cycle, using markers?
The first marker ("Loop Start") would be the start of the loop, and the second marker ("Loop End") would be the end of the loop.
It's probably easiest to split the layer at the loop beginning, remove extraneous keyframes before then, and then use your loopOut expression.
There's a little-known option with loopOut() to specific the number of keyframes back from the last one to use for the loop. There's another variation on loopOut called loopOutDuration() that allows you to specific the time back from the last keyframe for the looping section. Both of these are covered in the expression language reference [link].
It would be possible to write an expression that does what you describe, but you'd have to re-write the loopOut functionality from scratch, using valueAtTime().