how to i++ when new day

 
int i=0;
     
     if( .... ) //"when new day"
     {
     i++;
     dPriceHighAll=High[Highest(NULL, 0, MODE_HIGH,(iBarShift(NULL, 0, StrToTime(TimeToStr(dtTradeDate-(86400*i), TIME_DATE) + " " + sTimeBegin)))-(iBarShift(NULL, 0, StrToTime(TimeToStr(dtTradeDate-(86400*i), TIME_DATE) + " " + sTimeEnd))), (iBarShift(NULL, 0, StrToTime(TimeToStr(dtTradeDate-(86400*i), TIME_DATE) + " " + sTimeEnd))))];
     dPriceLowAll=Low[Lowest(NULL, 0, MODE_LOW,(iBarShift(NULL, 0, StrToTime(TimeToStr(dtTradeDate-(86400*i), TIME_DATE) + " " + sTimeBegin)))-(iBarShift(NULL, 0, StrToTime(TimeToStr(dtTradeDate-(86400*i), TIME_DATE) + " " + sTimeEnd))), (iBarShift(NULL, 0, StrToTime(TimeToStr(dtTradeDate-(86400*i), TIME_DATE) + " " + sTimeEnd))))];
     int EXP=23-StrToDouble(periodEnd);
     if(Hour()==2 && Minute()==30 &&Seconds()==0 )
           {
            Print("i=",i); 
           }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////   
           if(CountPendingOrderNow(OP_BUYSTOP)==0 && CountPendingOrderNow(OP_SELLSTOP)==0 && CountOrderHISTORY()==0 )
              {
               if(Hour()==2 && Minute()==30 &&Seconds()==0 )
                 {
                  int onebuystop1=OrderSend(Symbol(),OP_BUYSTOP,CanLoss/((MathAbs((dPriceHighAll-dPriceLowAll))/Point)*MarketInfo(Symbol(), MODE_TICKVALUE)),dPriceHighAll,0,dPriceLowAll,dPriceHighAll+(dPriceHighAll-dPriceLowAll),"onebuystop1",MagicNumber,EXP,clrGreen);
                  int onesellstop1=OrderSend(Symbol(),OP_SELLSTOP,CanLoss/((MathAbs((dPriceHighAll-dPriceLowAll))/Point)*MarketInfo(Symbol(), MODE_TICKVALUE)),dPriceLowAll,0,dPriceHighAll,dPriceLowAll-(dPriceHighAll-dPriceLowAll),"onesellstop1",MagicNumber,EXP,clrRed);
                 }
               }
     }
 
mql4 topic in mql4 section please.
 
Alain Verleyen:
mql4 topic in mql4 section please.

how to delete this topic

 
Boripath Boonrit:

how to delete this topic

I moved this topic to MQL4/MT4 section (no need to delete).

 
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. dtTradeDate-(86400*i)
    This assumes continuous time. Think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.) Also you don't want yesterday, you want the previous trading day.

  3. StrToTime(TimeToStr
    Drop that Code. All you're doing is taking a datetime, converting to a string, converting back to a datetime. Just get the date.
              Find bar of the same time one day ago - Simple Trading Strategies - MQL4 and MetaTrader 4 - MQL4 programming forum

  4. If you need n trading days ago, just get the time from the D1 chart using iTime. You must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  5. To answer your question, just do it like new bar code. Remember and look for a change in the date.
              New candle - MQL4 and MetaTrader 4 - MQL4 programming forum