on Spawn
set.$maxChickens: 20
set.$radius: 10
if entity.is.chicken
nearby.entity.chicken.$radius
set.world_tag_murderchickens: world_tag_murderchickens+1
if world_tag_murderchickens > $maxChickens
it.despawn
untag.world.murderchickens
Miiiight work. Not 100% sure, haven't used 'nearby' in a while.
Every time a chicken spawns, loop through every chicken near it in a $radius of 10. Increase a counter per chicken. If the counter goes over 20, kill every chicken after 20 is reached. Now that the chicken has been processed, delete the counter so the next one is ready when it spawns.