test

Tuesday, June 28, 2016

How to generate your own latency arbitrage expert

Many latency arbitrage expert advisors are on the internet. Most of them do not show their source code. Therefore the trader does not know what the expert is doing. In easy steps, with just a few lines of code, you can generate a basic latency arbitrage expert advisor which is under your full control. MetaTrader 4 "MT4" and Visual Studio Express give you everything you need and both are free. With these two applications you can setup your own low latency trading application. The latency depends mainly on your server location. If you locate your server next to a trading server the latency can be under one millisecond. The latency to your quote provider is also important. It's possible that your quote provider is in London and the trading server of your broker is in Asia. This means that the latency can be several milliseconds, because the difference in time and space is so large.

Please have a look on the following graphic which shows how this strategy works in general:




Now it becomes a bit more technical. You need two MT4 installations. The first one is your quote provider. A fast ECN broker is the best in most cases. The second MT4 installation is for your broker where you trade. Usually it's a Market Maker.

First you code a small program in the editor of MetaTrader which is included in MT4. The small program writes the quotes to a file. Every time new quotes are received the small program writes it to a file. For that you need a Dynamic Link Library "dll"   extension coded in C++, because MetaTrader just can write to his own home folder. Therefore it is impossible to exchange data between two terminals without an extension. The function of the dll is called every time new quotes come in and creates the file with the Bid and Ask price. The dll is written in Visual Studio Express. Not many lines of code are needed to finish that.

For the second MT4 you write a small dll function which reads your text file. If the quotes have changed in the text file, your Expert Advisor “EA” takes action.

What happens when the quotes have changed?

When the quotes have changed for the ECN or Market Maker the "EA" checks the difference between the quotes of the Market Maker and the ECN. If the difference is greater than three pips and the spread between the Bid and Ask of both is lower than two pips, you get an advantage of at least one pip. The EA checks that there are no open positions in that currency or stock. If there are no open positions the EA executes an order for the currency or stock where the gap occurred. Usually Fill or Kill orders are used. A Fill or Kill order means that the EA sends a limit order with the actual price. If this price is not available anymore, the order is deleted immediately. This is very important, because the price can drift away before the order arrives at the trading server.

Now you have your open position with at least one pip advantage. Many people turn the EA on when there is news. Very often after news is released, the prices of currencies and stocks make a large move. You can close your position after seconds, minutes or hours. The choice is yours. With this strategy you get very good trading setups that make it much easier to be profitable long term. Some EAs manage the whole process from opening to closing the position, including money management. It's important that you consider the broker rules. Some do not allow it to close the position under five minutes.

No comments:

Post a Comment