take inspiration from this guide.
https://foisfabio.it/index.php/2023/08/20/mikrotik-failover-recursive/
Then integrate the script into DHCP client as explained in this other guide in the point fig.15
https://foisfabio.it/index.php/2024/03/09/mikrotik-fwa-vodafone/