Documentation

Last updated on 30. 1. 2016 by Mark Fric

Special trade history exporters for MetaTrader and Tradestation

Special trade exporters for MetaTrader and Tradestation were added in version 4.10.

They have two advantages:

  • they allow for “automatic” export of trades to a predefined CSV data file, without the need of saving report file manually
  • MAE (max open loss) and MFE (max open profit) is recorded for every trade. This is possible only for reports loaded this way and it will display MAE/MFE on the equity chart.

How to install custom trade exporters:

For Tradestation

  1. Import file SQEXPORTTRADES.ELD into Tradestation using File -> Import/Export EasyLanguage -> Import EasyLanguage File (ELD). The file is located in /loaders folder in QA installation.
  2. then add command: Value90 = SQExportTrades(“C:Your_File_Name.csv”, 10) to the very end of your strategy.

The trading results will be then exported to the file C:Your_File_Name.csv.

This function has two parameters:
– file name including full path
– ATR period – ATR period that will be recorded whenthe trade is opened. It could be later used to compute for example volatility when the trade was opened. You can set 1 if you don’t want to use it.

For MetaTrader

  1. Copy the file SQLogTrades.mqh into your MQL4Include folder – you can find the folder in MetaTrader4 in File -> Open Data Folder. The file is located in /loaders folder in QA installation.
  2. In your EA you have to do four things:
    1. include SQLogTrader.mqh file into your EA using #include<SQLogTrades.mqh
    2. add command sqInitLog(“Your_File_Name.csv”, 0, 10); to OnInit() / init() function.
      If this function doesn’t exist in your EA you have to create it.
    3. add command sqCloseLog(); to onDeinit() / deinit() function.
      If this function doesn’t exist in your EA you have to create it.
    4. add command sqLogTrades(); to the very beginning of OnTick() / start() function.

The trading results will be then exported to the file /tester/files/Your_File_Name.csv.
You can get to the tester folder using MetaTrader4 in File -> Open Data Folder

This function has three parameters:
– file name including full path
– magic number – if not 0 it will record only trades with given magic number
– ATR period – ATR period that will be recorded whenthe trade is opened. It could be later used to compute for example
volatility when the trade was opened. You can set 1 if you don’t want to use it.

Example – old MQL code style:


#include<SQLogTrades.mqh>

int init() {
sqInitLog(“My_EA_Results.csv”, 0, 10);

return(INIT_SUCCEEDED);
}

void deinit(const int reason) {
sqCloseLog();

}

void start() {
sqLogTrades();


}

Example – new MQL code style


#include<SQLogTrades.mqh>

int OnInit() {
sqInitLog(“My_EA_Results.csv”, 0, 10);

return(INIT_SUCCEEDED);
}

void OnDeinit(const int reason) {
sqCloseLog();

}

void OnTick() {
sqLogTrades();


}

Was this article helpful? The article was useful The article was not useful

Subscribe
Notify of
5 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Daniel
Daniel
2. 7. 2018 12:33 pm

Hi,
I would need an information. I should use your software to access multiple mt4 accounts opened and started on the same virtual machine simultaneously. All data (the detailed reports of the trade of the individual mt4 accounts) then exported to a MySQL database.
Is your software suitable for this operation?

Regards

Bee trader
Reply to  Daniel
18. 8. 2021 10:21 am

No it’s not suitable. Find something like python to import the results into your mysql database.

chris
chris
17. 12. 2021 12:02 pm

Hi,

I can’t get this to work with MT4. It only logs around 5 trades out of 86. I followed the instructions outlined above.

Regards

Lucas Koster
Lucas Koster
10. 12. 2022 5:30 pm

Hello is this also available for MT5?

tomas262
Admin
Reply to  Lucas Koster
12. 12. 2022 2:17 pm

Hi, we do not have the MT5 version yet unfortunately