Let’s write script that reboot mikrotik device if no ping to gateway.
First of all lets go to menu System -> Script in Winbox and create new script with name PingCheck

Write this core in field Source:
:if ([/ping 10.21.2.1 count=10] = 0) do={ /system reboot }
Don’t forget to change IP 10.21.2.1 to yours gateway IP address.
Now lets create scheduler that will start this script every 10 minutes. Go to menu System -> Scheduler and create new task:

Write some name of new task, set start date Jan/01/1970, time 00:00:00 and run interval 00:10:00. Don’t forget to write script name PingCheck in field On Event.
That’s all.