Download MetaTrader 5

How to determine when new tick come

To add comments, please log in or register
Why to sell products in MetaTrader AppStore? Find that out from the article!
Mohammad Ali
19571
Mohammad Ali 2014.01.06 15:54 

Dear guy.

I made a EA. with also loop code for show time left for candle close. code is below. but it is not work perfect. sometime new candle but still countdown, countdown not reset. i want. when new tick come then countdown will be reset and update with main time. and when tick not come then loop run.

int start(){
while(!(IsTesting() || IsStopped() || isRLastTime)){

    CloseTime(isUPTrend);
    WindowRedraw();
    Sleep(1000);
}
   return (0);
}

void CloseTime(bool isUp)
{
  
  //Print(LastTime+"   "+iTime(NULL,0,0));
  if (LastTime==0){
    z=0;
    z=Time[0]+Period()*60-CurTime();
    LastTime=iTime(NULL,0,0);
  }else{
    if(z>0){z=z-1;}else{isRLastTime=true;}
    Print(z);
  }

  m=z;
  s=m%60;
  m=(m-s)/60;

  string _sp="",_m="",_s="";
  if (m<10) _m="0";
  if (s<10) _s="0";
  
  if (isUp==true){
    _sp = "CURRENT TREND: UP";
  }else{
    _sp = "CURRENT TREND: Down";
  }
  
  ObjectSetText(objname,_sp+"    Next Bar in "+_m+DoubleToStr(m,0)+":"+_s+DoubleToStr(s,0), 10, "Courier", Clock_Color);
  return(0);
}
Ubzen
5394
Ubzen 2014.01.06 18:09  
capilta:

Dear guy.

I made a EA. with also loop code for show time left for candle close. code is below. but it is not work perfect. sometime new candle but still countdown, countdown not reset. i want. when new tick come then countdown will be reset and update with main time. and when tick not come then loop run.

Get rid of the while()loop and work with ticks as they come.
To add comments, please log in or register