ExpertHistoryExample

Download script
Author: Copyright 2021, Yuriy Bykov

This script is designed as a specialized utility for MetaTrader 5 to capture and archive specific trading data during the backtesting process. Its primary purpose is to act as a "data logger" that records key operational variables—such as currency pairs and profit targets—so they can be reviewed after a simulation is complete.

Core Logic Overview

The script operates through three distinct stages:

1. Setup and Identification Upon being launched, the script initializes a dedicated tracking object. It assigns a specific name and version to the trading activity it is monitoring. This ensures that when you review your results later, the data is organized and easily identifiable.

2. Parameter Registration During the initialization phase, the script gathers specific "input" values from the user settings. In this instance, it automatically identifies:

  • The specific financial instrument (Symbol) being traded.
  • The Take Profit (TP) level.
  • The Stop Loss (SL) level.

These details are registered into a history log, creating a digital "snapshot" of the rules applied to the trade.

3. Automated Exporting The most critical part of the logic occurs at the end of the testing cycle. The script includes a safety check to see if the data is being gathered from a standard backtest or an optimization run. If it detects a standard test, it triggers an export command. This action saves the accumulated parameters into a history file, allowing traders to extract and analyze how different settings performed without having to manually record every detail during the simulation.

2 Views
0 Downloads
0 Favorites
ExpertHistoryExample
//+------------------------------------------------------------------+
//|                                         ExpertHistoryExample.mq5 |
//|                                      Copyright 2021, Yuriy Bykov |
//|                        https://www.mql5.com/ru/code/37444/254294 |
//+------------------------------------------------------------------+
#property description "Examlple for usage CExportHistory class"
#property copyright "Copyright 2021, Yuriy Bykov"
#property link      "https://www.mql5.com/ru/code/37444/254294"
#property version   "1.00"

// 0. Include library with CExpertHistory class
#include <ExpertHistory.mqh>

// 1. Create object instance in global scope
string expertName = "SomeExpert";
string expertVersion = "1.00";     // Not required

CExpertHistory expertHistory(expertName, expertVersion);



//--- input parameters
input double   SL = 500.0;
input double   TP = 1000.0;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
//---
   expertHistory.AddParam("Symbol", Symbol());
   expertHistory.AddParam("TP", TP);
   expertHistory.AddParam("SL", SL);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
//---

}
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester() {
//---
   double ret = 0.0;
//---
   // 3. Add in OnTester() function call of Export() method:
   
   // If you want save history only in single tester run
   // do it only if it was not optimization run 
   if(!MQLInfoInteger(MQL_OPTIMIZATION)) { 
      expertHistory.Export();
   }
//---
   return(ret);
}
//+------------------------------------------------------------------+

Comments