bool checkDailyTarget(){
double tFloating = 0.0;
int tPos = PositionsTotal();
for (int i=tPos-1; i>=0; i--){
ulong ticket = PositionGetTicket(i);
if (ticket > 0){
tFloating += PositionGetDouble(POSITION_PROFIT) + PositionGetDouble(POSITION_SWAP);
}
}
double dailyHistory = getHistoryProfit();
double targetDaily = MathAbs(IN_DailyTarget);
return ((tFloating + dailyHistory) >= targetDaily);
}
double getHistoryProfit(){
double tHistoryProfit = 0.0;
datetime fromDate, toDate;
fromDate = iTime(Symbol(), PERIOD_D1, 10);
toDate = TimeCurrent();
if(!HistorySelect(fromDate, toDate))
{
Print("Failed to select trade history: ", GetLastError());
return (0);
}
int tHis = HistoryDealsTotal();
for (int i=tHis-1; i>=0; i--){
ulong dealTicket = HistoryDealGetTicket(i);
if(dealTicket == 0) continue;
//// Check if deal belongs to this EA (same symbol and magic number)
//if(HistoryDealGetString(dealTicket, DEAL_SYMBOL) != _Symbol)
// continue;
//if(HistoryDealGetInteger(dealTicket, DEAL_MAGIC) != MagicNumber)
// continue;
// Get deal properties
double dealProfit = HistoryDealGetDouble(dealTicket, DEAL_PROFIT);
//long dealType = HistoryDealGetInteger(dealTicket, DEAL_TYPE);
long dealEntry = HistoryDealGetInteger(dealTicket, DEAL_ENTRY);
// Only process closed deals (DEAL_ENTRY_OUT)
if(dealEntry != DEAL_ENTRY_OUT)
continue;
tHistoryProfit += dealProfit;
}
return (tHistoryProfit);
}