我的意思是,如果专家在一天中的任何时间开仓,此后就不要在当天开仓
我尝试用这种方法检查这一点,并在开新仓之前将其入池,但它不起作用
bool IsOneDayPassedSinceLastDeal(字符串符号) {
int totalDeals = HistoryDealsTotal();
if (totalDeals == 0)
return true;
for (int i = totalDeals - 1; i >= 0; i--)
{
ulong dealTicket = HistoryDealGetTicket(i);
string dealSymbol = HistoryDealGetString(dealTicket, DEAL_SYMBOL);
if (dealSymbol == symbol)
{
datetime openTime = HistoryDealGetInteger(dealTicket, DEAL_TIME);
datetime currentTime = TimeCurrent();
int timeDifference = currentTime - openTime;
int secondsInDay = 24 * 60 * 60;
if (timeDifference < secondsInDay)
return false;
}
}
// If no deal was found for the symbol within the last day, return true
return true;
}
解决方案编辑此方法
bool IsOneDayPassedSinceLastDeal() {
MqlDateTime currentDate;
TimeCurrent(currentDate);
int currentDay = currentDate.day;
int lastDay = _lastPositionTime.day;
if (currentDay == lastDay ) {
return false;
} else {
return true;
}
}
定义 MqlDateTime _lastPositionTime; 作为公共变量