//+------------------------------------------------------------------+ //| Reporter.mq5 | //| Copyright 2026, MasterOfPuppets | //| https://forge.mql5.io/masterofpuppets/mql5 | //+------------------------------------------------------------------+ #ifndef MASTER_OF_PUPPETS_LIB_REPORTER_MQ5 #define MASTER_OF_PUPPETS_LIB_REPORTER_MQ5 #include #include #property copyright "Copyright 2026, MasterOfPuppets" #property link "https://forge.mql5.io/masterofpuppets/mql5" //+------------------------------------------------------------------+ //| Reporter initialization function | //+------------------------------------------------------------------+ void Reporter::Init(CDealInfo *srcDealInfo, const int srcLastProfitsSize) { m_dealInfo = srcDealInfo; m_lastProfitsSize = srcLastProfitsSize; } //+------------------------------------------------------------------+ //| Calculate total last profit function | //+------------------------------------------------------------------+ void Reporter::CalculateTotalLastProfit() { for(int i = 0; i < m_lastProfits.Total(); i++) { LastProfit *lastProfit = m_lastProfits.At(i); m_totalLastProfit += lastProfit.profit; } } //+------------------------------------------------------------------+ //| Get message function | //+------------------------------------------------------------------+ const string Reporter::GetMessage(const ENUM_DEAL_TYPE enumDealType) const { switch(enumDealType) { case ENUM_DEAL_TYPE::DEAL_TYPE_BUY: return MESSAGE_SELL; case ENUM_DEAL_TYPE::DEAL_TYPE_SELL: return MESSAGE_BUY; } return ""; } //+------------------------------------------------------------------+ //| Get suffix function | //+------------------------------------------------------------------+ const string Reporter::GetSuffix(const long dealReason) const { if(dealReason == DEAL_REASON_SL) { return "(stop loss) "; } if(dealReason == DEAL_REASON_TP) { return "(take profit) "; } return ""; } //+------------------------------------------------------------------+ //| Last profits initialization function | //+------------------------------------------------------------------+ void Reporter::InitLastProfits() { m_lastProfits.Clear(); m_totalLastProfit = 0.0; datetime now = TimeCurrent(); datetime yesterday = now - 86400; // PERIOD_D1 * 60 HistorySelect(yesterday, now); int lastProfitIndex = 0; for(int i = HistoryDealsTotal() - 1; i >= 0; i--) { if(!m_dealInfo.SelectByIndex(i)) { continue; } if(m_dealInfo.Entry() == DEAL_ENTRY_IN) { continue; } if(lastProfitIndex >= m_lastProfitsSize) { break; } double dealProfit = m_dealInfo.Profit(); long dealReason = HistoryDealGetInteger(m_dealInfo.Ticket(), DEAL_REASON); if(IsStandardDealReason((int) dealReason)) { m_lastProfits.Add(new LastProfit(GetMessage(m_dealInfo.DealType()), dealProfit, GetSuffix(dealReason))); lastProfitIndex++; } } CalculateTotalLastProfit(); } //+------------------------------------------------------------------+ //| Get last profits function | //+------------------------------------------------------------------+ const CArrayObj* Reporter::GetLastProfits() const { return GetPointer(m_lastProfits); } //+------------------------------------------------------------------+ //| Get total last profit function | //+------------------------------------------------------------------+ const double Reporter::GetTotalLastProfit() const { return m_totalLastProfit; } #endif //+------------------------------------------------------------------+