string CheckReport()
{
static stringProfitReport = "";
static intTimeToReport = 0;
static intTradeCounter = 0;
#define Daily0
#define Weekly1
#defineMonthly2
#defineAll3
if (TradeCounter != HistoryTotal()) {
TradeCounter = HistoryTotal();
TimeToReport = 0;
}
if (TimeLocal() > TimeToReport) //发生异动
{
TimeToReport = TimeLocal() + 300;
doubleProfit[10], Lots[10], Count[10];
ArrayInitialize(Profit,0);
ArrayInitialize(Lots,0.000001);
ArrayInitialize(Count,0.000001);
int Today = TimeCurrent() - (TimeCurrent() % 86400);
int ThisWeek = Today - TimeDayOfWeek(Today)*86400;
int ThisMonth = TimeMonth(TimeCurrent());
for (int i = 0; i < HistoryTotal(); i++)
{
if ( OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol() && OrderMagicNumber()== Magic && OrderCloseTime() > 0 ) {
Count[All]+= 1;
Profit[All]+= OrderProfit() + OrderSwap()+OrderCommission();
Lots[All]+= OrderLots();
if (OrderCloseTime() >= Today) {
Count[Daily]+= 1;
Profit[Daily]+= OrderProfit() + OrderSwap()+OrderCommission();
Lots[Daily]+= OrderLots();
}
if (OrderCloseTime() >= ThisWeek) {
Count[Weekly]+= 1;
Profit[Weekly]+= OrderProfit() + OrderSwap()+OrderCommission();
Lots[Weekly]+= OrderLots();
}
if (TimeMonth(OrderCloseTime()) == ThisMonth) {
Count[Monthly]+= 1;
Profit[Monthly]+= OrderProfit() + OrderSwap()+OrderCommission();
Lots[Monthly]+= OrderLots();
}
}
}
ProfitReport = "\n\nPROFIT REPORT" +
"\nToday: $" + DoubleToStr(Profit[Daily],2) +
"\nThis Week: $" + DoubleToStr(Profit[Weekly],2) +
"\nThis Month: $" + DoubleToStr(Profit[Monthly],2) +
"\nAll Profits: $" + DoubleToStr(Profit[All],2) +
"\nAll Trades: " + DoubleToStr(Count[All],0) + " (Average $"+DoubleToStr(Profit[All]/Count[All],2)+" per trade)"+
"\nAll Lots: " + DoubleToStr(Lots[All],2) + " (Average $"+DoubleToStr(Profit[All]/Lots[All],2) +" per lot)";
}
return (ProfitReport);
}
微信公众号:天泓评测
发表评论