Coming to your original question, of course you can write your own scripts to monitor HADR and perform takeovers when required. In effect, you are developing a cluster software-both monitoring part and the agent. So, do not underestimate the complexity and effort required to get a proper set of scripts working.
Your monitoring part is more complex than the agent part. If you have another cluster software that provides a facility to develop your own agents, then you can of course do it.
a) Availability of Server
b) Availability of Instance
c) Network interconnect between the pair.
These are the three areas that hadr monitoring focusses on.
Based on your monitoring, you have to decide when each of these incidents have occurred, and take appropriate action.
Take into account the 'split-brain' scenario.
HTH atleast to some extent
Sathyaram