how to get the time of the lastbar ? - debug problem

 

Dear All

I have some problem in getting the Datetime of the lastbar, when I want to memorize the static variable as in iNewBar function, in running backtest it runs ok, so we can avoid over trade, and just only one entry, but when I check using debugging, I found that the date save in static variable is not the current running of the history bar's datetime, but the date of the last bar which appear in the current chart,

for example, the trade begin at 2022-05-01 00:00, and the local time now is 2022-06-10 08:00, so when the first bar time I save in the static variable, in the run of backtest, it's run well that the last bar is 2022-05-01, but when I check using debugging, I see that the static variable not record the 2022-05-01 00:00, instead : 2022-06-10 08:00, so I have using time[[], itime(NULL,0,0), still cannot to get the exact runngin backtest history last bar datetime, instead always the last time of the real time chart, so How to get the really last datetime of the history running last datetime ?

many thank if can solve this problem

thanks, bob

 
Indicator or EA? MT4 or MT5?
 
Bob Tanujaya: I see that the static variable not record the x instead :y, s

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

 
William Roeder #:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

<Deleted>

 
Bob Tanujaya #:

<Deleted>

William Roeder #:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.
     How To Ask Questions The Smart Way. (2004)
          Be precise and informative about your problem

We can't see your broken code.

 

please check the img file also, will describe what my problem is, sorry it's the first time I post in forum, and now learn to post any problem, and now I don't know how to paste the picture in the forum, so don't need to click the link of the image file.

thanks for the help

rgds bob

 

it seems than I failed to sent the detail code, now I try to sent once more (sorry, this is my first time post in the forum)

<Deleted>

 

You've been told twice to post your code correctly

William Roeder #:

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using Code button) or attach the source file.

Including the high-lighted link from William

Please use the code button (Alt+S) when pasting code.

 

it seems than I failed to sent the detail code, now I try to sent once more (sorry, this is my first time post in the forum)

***

 

may be can try this:

//extern datetime Day1 = D'2022.06.01 00:05';
datetime barD1;
bool tradeNow = false;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {

// declare variable for debuging check
   /*
   datetime static _static_daytime=0;
   datetime _Time = Time[0];

   if(IsTesting()) {
      if(CheckEntry(Day1) && (_static_daytime!=Time[0])) {
         if(OrderSend(NULL,OP_BUY,0.1,Ask,30,0,0,NULL)) {}
         _static_daytime=Time[0];
      }
   }
   */
   if(barD1!=iTime(NULL,PERIOD_D1,0)){
      barD1=iTime(NULL,PERIOD_D1,0);
      //if(OrderSend(NULL,OP_BUY,0.1,Ask,30,0,0,NULL)) {}
      tradeNow = true;      
   }
   //---
   if(tradeNow){
      //--- tambahkan Trigger utk entry signal  
      if(OrderSend(NULL,OP_BUY,0.1,Ask,30,0,0,NULL)) {}
      tradeNow = false;
   }
   
}
 
Agus Sulaiman #: may be can try this:
      if(OrderSend(NULL,OP_BUY,0.1,Ask,30,0,0,NULL)) {}

Be careful with NULL.

  1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
  2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
  3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
  4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
  5. Cloud Protector Bug? - MQL4 programming forum (2020)
Reason: