What is Robin Watchdog
Robin Watchdog is an active monitorization solution for Metatrader. It has two parts: the client and the server.
The client is an expert advisor running on Metatrader 4 that is constantly monitoring the market and the broker. The monitorization is active, so:
- It checks if the broker is available
- It monitors the lag to the server
- It monitors the actual time it takes to execute orders
- It is even able to activate intense monitoring at times when your strategy is near to give an entry signal
- It "wakes up" the connection to the broker seconds before placing a trading order
The server is a PHP application to receive information from all installations being monitored.
How to use Robin Watchdog
By default Robin Watchdog will:
- Send monitorization information to a remote server.
- Activate the connection to your broker 30 seconds before closing a bar (when your EA is about to trade).
Sending monitorization information to a remote server
Every minute Robin Watchdog will call your watchdog server. This call will be a simple HTTP GET call with your account information and the timestamp of the server passed as parameters. So the URL called will be something like this:
The server will then be able to use those two variables for monitoring. You can use very advanced monitorization software to perform customized monitorization as long as it accepts this kind of updates (most monitorization software available will accept this).
If you want just a simple monitorization solution (or you want to build your own solution), you can start from our sample server (see watchdog.php). This server will just create or update a file named <account>.html with the timestamp inside. From this you can monitor the status of all your accounts by just being sure that every minute those files are updated in the server.
Our watchdog.php sample server uses basic http authentication provided by the web server. This is not really needed, but if you run the monitorization on production server you will want to implement some kind of security.
watchdog.php should work out of the box as long as the "checks" directory exists on the server.
You will need to configure the client (robin-watchdog.mq4) to access your server. This is easy, as you will just need to set the URL for your watchdog server. See the following image to know what to modify:
Checking market conditions and activating connection with the broker
In addition to simply monitoring and sending the status of your EA to the monitorization server, Robin Watchdog allows you to "activate" the connection to the broker when a trading decission is about to happen.
When using TCP communications a link have to be created first (which is a relatively slow process). Once the application ends using this link, the link is kept open for some time to avoid the initial step. A long time can happen between two trading operations, so usually the connection has to be opened every time, wasting precious time. What Robin Watchdog does is to perform a dummy operation some seconds before so that the connection is still opened and active when the real trade happens.
Obviously Robin Watchdog cannot know by default when your EA is going to trade, so you need to define this conditions into Robin Watchdog. To do that you just need to define the market situation you want inside the "check_hot_status" function.
The "check_hot_status" function is executed every tick. If this function returns "True" and the close of the bar will happen in less than what is defined in "secondsBefore" variable (30 seconds by default) the routine to activate the connection with the broker is called.
Within Robin-Watchdog.mq4 code you will see an example of the "check_hot_status" function, which will work for a simple 20/50 Moving Average crossover strategy:
- Every tick the watchdog will check if there is a Moving Average cross
- If there is a cross, that could indicate that at the close of the bar our EA will probably want to perform an operation (either open or close) once the bar is closed.
- If 30 seconds before the close of the bar the conditions of the cross still apply we refresh the connection, so that when the real trade happens, it will be performed as fast as possible.
To check that proper market conditions exists, Robin Watchdog creates or updates a pending order with the minimum lotsize 500 pips far away from the price (configurable). The simple fact that this order can be created or updated tells us that proper trading conditions are present. This order is updated constantly so it is kept far away from the price to avoid accidental triggering.