Automatically Change Between 2 Frequencies when CCQ is low

Hi, please i need a script that can switch between 2 frequencies.

I have a wireless link for 20Km above the ocean, and i have ccq 100%/100% and signal -58/-58 (mikrotik board 922 + 30dbi antenna)

the problem is minimum 3 to 5 times per day i got high latency and low ccq (27% - 40%) with signal (-64/-78) when i change the frequency from 6020 to 4990 it work for 6 hours minimum.

please i need the script to automatically change between 1st freq and 2nd one when link is down or low ccq.

Thank you in advance.

Try this:
:foreach i in=[/interface wireless registration table find ap=no]
do={
:local txccq [/interface wireless registration-table get $i tx-ccq]
:local rxccq [/interface wireless registration-table get $i rx-ccq]
:local freq [/interface wireless get 0 frequency]
:if ($txccq < “70” && $rxccq < “70” && $freq = 6020) do={
/interface wireless set 0 frequency=4990
:log info message=“frequency change to $freq”
}
:if ($txccq < “70” && $rxccq < “70” && $freq = 4990) do={
/interface wireless set 0 frequency=6020
:log info message=“frequency change to $freq”
}
}