i founded sotution making boss bar depended on nearest mob -
/bossbar add minecraft:ne 1
/give @a minecraft:repeating_command_block
put this command inside repeating command block and make sure its repeat, unconditional, always active
execute as @a at @s run bossbar set minecraft:1 name {"selector":"@e[type=!player,limit=1,sort=nearest]"}
/give @a minecraft:chain_command_block , put this command inside chain command block next to repeateble one depended which arrow it facing, make sure its chain, unconditional, always active
execute as @a at @s store result bossbar minecraft:1 value run data get entity @e[limit=1,sort=nearest,type=!player] Health
put another chain command block to chain command block depended which arrow it facing and and put this command inside, turn again chain, unconditional, always active
execute as @a at @s store result bossbar minecraft:1 max run data get entity @e[limit=1,sort=nearest,type=!player] Attributes[0].Base
dont put another block and set this command , just type it in minecraft
/bossbar set minecraft:1 players @a
now make sure spelling of your own created command is correct and it should work