HomePHP Building an E-mini Trading System Using PHP and Advanced MySQL Queries
Building an E-mini Trading System Using PHP and Advanced MySQL Queries
This article shows illustrative examples of how PHP and some advanced MySQL queries can be used to build an online trading system. For simplicity, we will be featuring one of the most common stock indexes: the S&P 500 index.
As of September 2009, there was no currently working trading system on the Internet powered by PHP and MySQL despite the platform's popularity among open source communities.
A trading system is used to enter and exit a trade in a stock or futures market. Although in exiting a trade to grab profits and control losses, money management is a more useful tool than a trading system.
To create a fully working trading system, you need the following processes:
The raw data should be taken from a reputable source for S&P 500 index data. In this article, we will be using Yahoo! Finance data. The export file type is mostly .csv and Excel, so you first need to export the raw data to the MySQL database. (See details below)
The heart of the process is the trading system. It is a method for analyzing raw data and making judgments. Every trader has his or her own trading system to follow, but in this example, we will use the following rules:
Rule 1: Define Delta as the difference between 50 days moving average and 200 moving average. If the delta is positive, it indicates a bullish trend, otherwise it's bearish. You can read more about moving averages.
Rule 2: Define % Strength of the trend as Delta/MA 200. This quantifies the strength of the trend. Apply historical data (define limits) for judgment (computation of limits is out of scope for this tutorial). This is more like a trend confirmation.
Use PHP to display the data in HTML tables while using MySQL advance queries (computing average and getting index data) to do some calculations of the moving average.