在MetaTrader Terminal 4中,您可以选择创建详细的报告。您可以使用html格式获取帐户历史记录的结果。
我正在寻找一个自动生成这个html文件的函数。
截至2018-02,MQL4语言语法中没有任何此类自动生成报告功能。
人们可以使用自定义代码,享受在OnDeinit()
+ OnTester()
处理程序中启动它的能力。
这是我构建的解决方案。该方法创建两个csv,使用date和SYMBOL或date和ACCOUNT命名。在ACCOUNT中都是交易。在SYMBOL中只是符号交易。创建csv后,我通过java自动将它们导入MySQL数据库。
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";
}
//+------------------------------------------------------------------+