Bar Time countDown become negative

 

Bar Time countDown : m=Time[0]+(Period()*60)-TimeCurrent( ) ;

this code run well in regular tick order, but...if i run in simulate tick every 1 second..become negative at next bar & so on

any idea what wrong..? thanks
 
Repions:

Bar Time countDown : m=Time[0]+(Period()*60)-TimeCurrent( ) ;

this code run well in regular tick order, but...if i run in simulate tick every 1 second..become negative at next bar & so on

any idea what wrong..? thanks

If you have missing bars you will get -ve values.

I did this . . .

   M1Time = StringConcatenate("M1: 00:",(60 - TimeSeconds(TimeCurrent( )) ) );
   M5Time = StringConcatenate("M5: ", 4 - ( TimeMinute(TimeCurrent())% 5),":",(60 - TimeSeconds(TimeCurrent( )) ) );
   M15Time = StringConcatenate("M15: ", 14 - ( TimeMinute(TimeCurrent())% 15),":",(60 - TimeSeconds(TimeCurrent( )) ) );
   M30Time = StringConcatenate("M30: ", 29 - ( TimeMinute(TimeCurrent())% 30),":",(60 - TimeSeconds(TimeCurrent( )) ) );
   H1Time = StringConcatenate("H1: ", 59 - ( TimeMinute(TimeCurrent())% 60),":",(60 - TimeSeconds(TimeCurrent( )) ) );
   H4Time = StringConcatenate("H4: ", 3 - TimeHour(TimeCurrent()) + TimeHour(iTime(NULL, PERIOD_H4, 0)) , ":", 59 - ( TimeMinute(TimeCurrent())% 60),":",(60 - TimeSeconds(TimeCurrent( )) ) );
   D1Time = StringConcatenate("D1: ", 23 - TimeHour(TimeCurrent()) + TimeHour(iTime(NULL, PERIOD_D1, 0)) , ":", 59 - ( TimeMinute(TimeCurrent())% 60),":",(60 - TimeSeconds(TimeCurrent( )) ) );
 
Are you returning from start() or calling RefreshRates() after Sleep() so Time[0] updates?
 
WHRoeder:
Are you returning from start() or calling RefreshRates() after Sleep() so Time[0] updates?
int start(){
if(!IsTesting() || IsStopped()) {
   int hwnd=WindowHandle(Symbol(), Period());
   int msg = RegisterWindowMessageA("MetaTrader4_Internal_Message");
         while(!IsStopped()){
            main() ;
            PostMessageA(hwnd, msg, 2, 1);  // produce fake ticks
            Sleep(1000);


         }
   }  else main();
}

int main()  {
 //  if(!IsTesting()) 
   { DrawTimeBar();DrawPriceUpDn();  CallIndi(); }
     InitVar();   DrawInfo();
if (iOpenTimeBar == Time[0])  return(0);     
   iOpenTimeBar = Time[0]; 

  refres();   // RefreshRates() in

....

return(0);
}
 
WHRoeder:
Are you returning from start() or calling RefreshRates() after Sleep() so Time[0] updates?

it seems the problem is solved if I added RefreshRates() after sleep(), but did call the RefreshRates() too often will make the server mad ?

Thanks Much WHRoeder

Thanks RaptorUK ..I save your code..In case still problematic
Reason: