In MetaTrader Terminal 4, there is an option to create a detailed Report. You get results of your account history in an html-format.
I am searching for a function which generates this html-file automatically.
In MetaTrader Terminal 4, there is an option to create a detailed Report. You get results of your account history in an html-format.
I am searching for a function which generates this html-file automatically.
As of 2018-02 there has not been any such auto-generate Report feature in the MQL4 language syntax available.
One may resort to use a custom-defined code, enjoying an ability to launch it in either of OnDeinit()
+ OnTester()
handlers.
This is my solution i have build. The method creates two csv, named them with date and SYMBOL or date and ACCOUNT. In ACCOUNT are all trades. In SYMBOL just the symbol trades. After create the csv i import them automatically via java into a MySQL database.
void ExportHistory()
{
int symbolHandle;
symbolHandle=FileOpen(Historyfile(Symbol()),FILE_SHARE_READ|FILE_TXT|FILE_WRITE);
if(symbolHandle>0)
{
for(int index=0;index<OrdersHistoryTotal();index++)
{
if(OrderSelect(index,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol())
{
string ticket=IntegerToString(OrderTicket());
string openTime=TimeToString(OrderOpenTime(),TIME_DATE|TIME_SECONDS);
string type=EnumToString((ENUM_ORDER_TYPE)OrderType());
string size=DoubleToString(OrderLots(),2);
string item=OrderSymbol();
string openPrice=DoubleToString(OrderOpenPrice(),Digits);
string stoploss=DoubleToString(OrderStopLoss(),Digits);
string takeprofit=DoubleToString(OrderTakeProfit(),Digits);
string closeTime=TimeToString(OrderCloseTime(),TIME_DATE|TIME_SECONDS);
string closePrice=DoubleToString(OrderClosePrice(),Digits);
string swap=DoubleToString(OrderSwap(),2);
string profit=DoubleToString(OrderProfit(),2);
string msg=ticket+";"+openTime+";"+type+";"+size+";"+item+";"+openPrice+";"+stoploss+";"+takeprofit+";"+closeTime+";"+closePrice+";"+swap+";"+profit;
FileWrite(symbolHandle,msg);
}
}
}
FileClose(symbolHandle);
}
int mainHandle;
mainHandle=FileOpen(Historyfile("ACCOUNT"),FILE_SHARE_READ|FILE_TXT|FILE_WRITE);
if(mainHandle>0)
{
for(int index=0;index<OrdersHistoryTotal();index++)
{
if(OrderSelect(index,SELECT_BY_POS,MODE_HISTORY))
{
string ticket=IntegerToString(OrderTicket());
string openTime=TimeToString(OrderOpenTime(),TIME_DATE|TIME_SECONDS);
string type=EnumToString((ENUM_ORDER_TYPE)OrderType());
string size=DoubleToString(OrderLots(),2);
string item=OrderSymbol();
string openPrice=DoubleToString(OrderOpenPrice(),Digits);
string stoploss=DoubleToString(OrderStopLoss(),Digits);
string takeprofit=DoubleToString(OrderTakeProfit(),Digits);
string closeTime=TimeToString(OrderCloseTime(),TIME_DATE|TIME_SECONDS);
string closePrice=DoubleToString(OrderClosePrice(),Digits);
string swap=DoubleToString(OrderSwap(),2);
string profit=DoubleToString(OrderProfit(),2);
string msg=ticket+";"+openTime+";"+type+";"+size+";"+item+";"+openPrice+";"+stoploss+";"+takeprofit+";"+closeTime+";"+closePrice+";"+swap+";"+profit;
FileWrite(mainHandle,msg);
}
}
FileClose(mainHandle);
}
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string Historyfile(string type)
{
string date=TimeToString(TimeCurrent(),TIME_DATE);
StringReplace(date,".","");
return date+"_"+type+".csv";
}
//+------------------------------------------------------------------+