Hi
The standard amount formula to green or red a back bet is (bm_backp*bm_backa)/lay_price
I think lay_price2 is too close, especially inplay, can be gone in millisecs.
Try this which will submit a lay bet 10 ticks above the current best lay price (replace 10 with any amount of ticks):
LAY
Price: r_ticks(lay_price,10)
Amount: (bm_backp*bm_backa)/lay_price
Conditions:
selections back matched is greater than 0
....plus any further conditions to confirm the selection is running a loss
Now, this will always work smoothly in test mode, because it will use lay_price and distribute evenly. You will have to try with small stakes in real mode because Betfair will match your lay bet which is submitted 10 ticks above lay_price, at the best available price, if there is sufficient unmatched volume, and then move to the next best price etc.
Hope that makes sense.