Home About Contact
ForexForums.org




Reply
Old 05-17-2008, 09:14 PM   #1 (permalink)
Administrator
 
kokas's Avatar
 
Join Date: Sep 2006
Location: Portugal
Posts: 507
Order History Logger

Order History Logger
By Market Phantasm

Disclaimer

This program is currently in a BETA stage. Meaning, it hasn’t been thoroughly tested. Please perform your own quality assurance of the data itself before making any decisions based upon the data. If you find any data issues, please let me know at marketphantasm[ at ]gmail.com

Feedback

I’d be more than happy to receive any comments or suggestions you may have. Simply e-mail me. Also, if you come up with a profitable EA or settings to make an EA profitable please let me know. The whole point of this is so I can do this analysis myself; however, I’d appreciate if you share your results. If you have something that is profitable, please share it with me, even if it’s private. This took quite a few hours to write.

Purpose

The purpose of the logger is to extract your order history into a comma separated format so you can analyze your trades in Excel, import the data into a database, and/or write a custom program to analyze the data. It extracts data that will be useful in making your trades or Expert Advisors more profitable. It exports the basic data that Meta Trader displays, plus more advanced data such as the highest profit in pips, the highest loss in pips, etc. The order history data can be generated from the “Order History” EA, or, you can call the function from your custom EA.

To Note

  • The file will be saved in the Experts\Files folder. Due to security restrictions within Meta Trader it can’t be saved in another folder. If the file doesn’t exist it will automatically be created. You can pass in the file name as an input parameter when attaching the EA to the chart.
  • The chart, timeframe, and/or currency pair that the EA is attached to doesn’t matter. It doesn’t affect the order history results. However, the EA will export the entire order history once when you first attach it to the chart.
  • If you notice some values are blank, specifically order history duration type values such as the total volume, highest price, lowest price, etc, check your history for the 1 minute bars. The most likely cause is that you don’t have the 1 minute history for that currency pair. To fix this, use the method of continuously pressing the “Home” key, or import the 1 minute bars for the given currency. It will not be able to calculate certain values unless there are 1 minute history bars for the order date range.
  • Due to the way Meta Trader functions it will only export orders that are visible in the account history. If you have any filters and you want your entire order history remove the filter. Conversely, if you only want orders from the past week you can set a date filter for the account history tab.

Usage Instructions

  • Copy the “Order History.ex4” file into your “MetaTrader 4\experts” directory.
  • Copy the “OrderHistory.csv” file into your “MetaTrader 4\experts\files” directory. Meta Trader only allows files to be written to this directory. Do not try to use another directory location.
  • For convenience, you may want to copy the Excel template file into the files directory as well.
  • Click View -> Navigator, Expand the Expert Advisors, and Drag & Drop the EA named “Order History” onto any chart.
  • In Windows Explorer double-click on the “OrderHistory.csv” file, which is located in the “MetaTrader 4\experts\files” directory. The file should open in Microsoft Excel.
  • Highlight the data by dragging and dropping all of the cells. If you don’t do this properly Excel will give you a Copy/Paste error when pasting into the Excel template. Make sure you select all of the data.
  • Open the “Order History.xls” file. Left click cell A2, right click, select paste special, select “Values”, and hit “OK” button. If you paste the data as usual it will overwrite the format settings. If you accidentally don’t choose values, the “Order History Template.xls” is meant as a backup file.

    Note: If you aren’t familiar with Excel’s Auto Filter feature, make sure you click on the header columns. A drop down list box will appear. For example, if you want to only analyze your buy trades, click on the order type column header cell, select “Buy” in the list, and it will only display the buy orders.

Possible Uses

If you are not a programmer I recommend using Microsoft Excel for your analysis. However, since the data is in CSV format, you can import the data into a database such as SQL Server or Microsoft Access. You can also create a custom program to read the file itself or from a database to do your analysis.

  • Determine the most profitable stop loss & take profit levels using the “Highest Profit Pips” & “Highest Loss Pips” values.

    Note that this has inherent limitations. It is limited to determining the most profitable levels using the prices of the duration of the trade. Therefore, for future trades on a demo account you may want to widen your stop loss and take profit so you can determine the best levels.
  • Run as many Expert Advisor’s under one account as you want. You can then analyze each EA’s results separately using the auto filter feature of Excel

    Note: If someone has time please compile a list of the most popular EA’s and their magic number. I’ll then modify the function to return the most possible list of EA’s name. Or, modify the source code and input the EA’s magic numbers that you are running.

To Do

  • Fix spread calculation.
  • Fix date and replace (some how, what mql 4 function?) “.” with a “/” so excel displays the dates properly.
  • Add an option of whether or not to include cancelled or expired orders.
  • Add a Magic Number extern parameter, and parameter to the function, to only export orders for a given magic number. This will allow the user to pass in a different file name and magic number, and export EA results into different files.
  • Save resources by not getting the order details if it's already been written to the file however, MQL 4 doesn't have an append option when opening & writing to the file, to fix
    • read entire file into a multi-dimensional array, storing ticket number used as PK, and order line
    • when looping through orders, if ticket is in the array, get order details from the array
    • otherwise, get using normal method by calling the Order Details function
  • Extract the following pieces of data:
    • Closed Percent Gain\Loss - Leveraged
    • Closed Percent Gain\Loss - Not Leveraged
    • Highest Profit Dollars
    • Highest Loss Dollars
  • Write a custom program to generate a report listing the profit/loss based on different combinations of stop losses & take profits. Allow the magic number or EA to be an input parameter.

Known Issues

  • Spread calculation.

Data Columns Exported

  • Order Ticket Number
  • Account Number
  • Account Company
  • Company Name
  • Account Name
  • Account Currency
  • Client Terminal Name
  • Demo
  • Server Address
  • Magic Number
  • Expert Advisor
  • Order Comments
  • Open Time
  • Close Time
  • Order Type
  • Order Symbol
  • Spread
  • Commission
  • Swap
  • Lots
  • Open Price
  • Stop Loss
  • Take Profit
  • Close Price
  • Total Volume
  • Avg. Volume
  • Highest Price
  • Lowest Price
  • Highest Profit Pips
  • Highest Loss Pips
  • Profit/Loss Pips
  • Profit/Loss Dollars
  • Local Date Time
  • Broker Date Time

Custom Data Exported

(Note, this isn’t available at this time. One method I’ve seen used is to be this extra custom data in the order comments.)

It’s important to note, that you can export your own custom data. To do this, you would modify the CustomData() function to export your custom data. You should return a comma delimited string.

The main reason you would want to do this is so you can identify any methods to filter or improve your EA’s results. For example, let’s assume that you had an EA that was based on a simple moving average, and you thought that adding a volume entry condition or filter would improve it’s results. Simply have the CustomData() function output the volume condition you are thinking of. This is some what harder than it seems, because most likely you will have to get the volume or volume indicator values for the bar right before the trade was placed. I’ll be writing a sample and releasing the sample in the next release. The point is, if you have the skills, you can export any custom data values you want to see if you added this condition/filter based on a given value would the profitability have been improved.
Attached Files
File Type: ex4 Order History.ex4 (13.1 KB, 10 views)
File Type: xls Order History.xls (210.5 KB, 9 views)
File Type: xls Order History - Template.xls (210.5 KB, 6 views)
File Type: xls Order History - Sample Data.xls (216.5 KB, 8 views)
File Type: csv OrderHistory - Sample Data.csv (3.8 KB, 7 views)
kokas is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Sedo - Buy and Sell Domain Names and Websites project info: forexforums.org Statistics for project forexforums.org etracker® web controlling instead of log file analysis

All times are GMT. The time now is 01:10 AM.
Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.