This week profit


//This Week Profit
      int WeekTime=iTime(NULL,PERIOD_W1,0);
      int WeekTimeLast=iTime(NULL,PERIOD_W1,1);
      double ProfitWeek=0;
      int WeekTrades=0;
      for(int z=(OrdersHistoryTotal()-1); z>=0; z--)
      if(OrderSelect(z, SELECT_BY_POS, MODE_HISTORY)==true)

         if(OrderCloseTime() >= WeekTimeLast ) { ProfitWeek = ProfitWeek=OrderProfit()+OrderSwap();WeekTrades++; }
This week profit, please where am I doing wrong?
         if(OrderCloseTime() >= WeekTimeLast ) { ProfitWeek = ProfitWeek=OrderProfit()+OrderSwap();WeekTrades++; }

Should be + :

         if(OrderCloseTime() >= WeekTimeLast ) { ProfitWeek += OrderProfit()+OrderSwap();WeekTrades++; }
thank you, but when I put it on, it still shows the wrong weekly profit :(
Zbynek Liska #:
thank you, but when I put it on, it still shows the wrong weekly profit :(
Probably because MT4 calculates it using the open time and not the close time.
You are also not filtering, non-trades in your loop.
  1. Do not assume history has only closed orders.
              OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017)

  2. Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum (2012)
              Taking the last profit and storing it in a variable | MQL4 - MQL4 programming forum #3 (2020)

  3. Total Profit is OrderProfit() + OrderSwap() + OrderCommission(). Some brokers don't use the Commission/Swap fields. Instead, they add balance entries. (Maybe related to Government required accounting/tax laws.)
              "balance" orders in account history - Day Trading Techniques - MQL4 programming forum (2017)

    Broker History
    Commission - «TICKET»
    Rollover - «TICKET»

    >R/O - 1,000 EUR/USD @0.52

    #«ticket»  N/A
    Balance update
    Financing (Swap: One entry for all open orders.)

and is there a solution how to specify it?
//------------------------Time calculations----------------------------

int TodaySeconds=(Hour()*3600)+(Minute()*60)+Seconds();
int YesterdayEnd=TimeCurrent()-TodaySeconds;
int YesterdayStart=YesterdayEnd-86400; 

//--------------------Analyze trade history------------------------------------

double ProfitToday=0,ProfitYesterday=0;
int YesterdayTrades=0,TodayTrades=0,FirstOnly=0;

for(int h=OrdersHistoryTotal()-1;h>=0;h--) // cycle
    if(OrderSelect(h,SELECT_BY_POS,MODE_HISTORY)==true) // select next
        // operations
           if(OrderCloseTime()>YesterdayStart){ // trade is young      
           if(OrderCloseTime()>YesterdayEnd){ ProfitToday=ProfitToday+OrderProfit()+OrderSwap(); TodayTrades++; }
           if(OrderCloseTime()<YesterdayEnd&&OrderCloseTime()>YesterdayStart){ ProfitYesterday=ProfitYesterday+OrderProfit()+OrderSwap(); YesterdayTrades++; }
          } // trade is young

      }// select
  }// cycle
daily and yesterday works correctly, I just don't know how to specify the week time?