I would like to start off this forum by announcing the MT4Analysis Project. This project will (eventually) deliver end-to-end analysis of MetaTrader V4 trading systems.
The backend consists of a program to parse MetaTrader V4 statement files into a database. The frontend will consist of a series of programs to analyze and present various trading performance statistics.
I have chosen to write this project using the Php language, SQLite as the backend database and Php/HTML/Javascript as the frontend.
The first part of this project has been written and is in alpha stage (working but not perfected). The first part is a Php program to parse an MT4 statement file and load an SQLite database from its contents.
The attached 'zip' file contains eveything you need to load the database. The parser program called 'mt4_sqlite_loader' is a Php CLI program. It is run from the command line or scheduler. It is not an HTTP program run from a web server.
Requirements:
Since Php is a server-side scripting language, you will need a web server with Php and Php CLI installed on your Windows PC (this is not as hard as you think...read on).
-Web server with Php module
-Php V5
-Php CLI capabilities
-Php PDO extension
-Php PDO SQLite V3 extension
This may sound complex but it does not have to be. The really good news is that there is a Windows distribution of
LAMP called
WAMP that just works right out of the box.
If you decide to use WAMP,
download the older 1.7.4 version. I have had problems with Php CLI and the SQLite database driver with newer versions. If you get a newer version to work with Php CLI, please let me know.
Assumptions:
I have used the
Php PDO interface which should greatly ease the ability to moving the backend to another database like MySQL.
The dates and times are loaded into the database as is (except for removing the periods). This will allow us to view the trades in a different time zone by calculating the new date and time on the fly.
Quick Start:
1. Make sure you have the requirements installed as above.
2. Create a new directory at the root level of the 'C' drive called 'mt4_sqlite_loader' and unzip the attached zip into it.
3. Copy the 'skelton.db' file located in the 'db' directory to another file like 'live.db' or 'demo.db'. The 'skelton.db' is a skelton of the SQLite database file with the tables defined without any trade data.
4. Crank up the loader:
a. start up a command prompt
b. change to MT4 loader directory by typing:
cd \mt4_sqlite_loader
c. parse and load with the command:
\wamp\php\php mt4_sqlite_loader.php db\live.db detailedstatement.htm
The above command assumes:
1. You are using WAMP installed in the default location.
2. The database file you decided to use is called 'live.db' in the 'db' sub-directory.
3. Your MT4 statement file has been placed into the 'mt4_sqlite_loader' directory.
The layout (schema) of the database file is in the file 'schema.txt' in the 'db' directory.
Only the loader exists right now but if you know SQL, you can download the
SQLite CLI program and type any queries that you want. Here are some I have been using:
-To verify the closing balance, first get the record with the highest ticket number:
select ticket from closedtrade where max(ticket);
Then, once you know the ticket number, display the record:
select * from closedtrade where ticket = ticketnum;
Where 'ticketnum' is the ticket number from the first query.
-To find all the different EA's in use in this account:
select distinct magic from closedtrade;
-To see how each EA is performing (total profit)
select total(pl) from closedtrade where magic = 123456;
Where '123456' is the EA magic/reference number that you got from the previous query.
One of the bad parts to MetaTrader is that the
broker 
can decide to consolidate your trading records and then the statement file is cleared of all previous trades. By using this database method, you will never loose any data.
The loader will only load closed trades that do not exist in the database. The ticket number is the key of the 'closedtrade' table and it must be unique. You can run the loader program as many times as you want.
I need some help with the loader program. I have tested it with some statement files but, obviously, not not covered every possibility. If you encounter any bugs using the loader please let me know.
Stay tuned for more.
Enjoy,
Rick