problem on the output position of the text object during back test

 
Dear all, 
I have a problem on the output position of the text object. As shown in the code below, the text object will be out put with the text set to be "the time current."
But from the screenshot below, the timecurrent is "2012.09.10", But the text position is located around"2012.08.30".
..... The two "TIMES" are so different. May I know why? and how to display the text at the time(or the bar) when the ObjectCreate() function is called? Many thanks for your help.

 

bool IsNewBarbyTime(){
  static datetime lastbar;
  datetime curbar = Time[0];
  if(lastbar!=curbar){
    lastbar=curbar;
    return(true);
  }
  else return(false);
}
int start(){
  double price=0.0;
  datetime time;
  static int obj=100,count=0;
  string objname="";
  objname="TXT"+obj;
  string txt="U";
  
  if(!IsNewBarbyTime()) return(0); //this ensures that the following code will be only excuted at the 1st tick of th bar.
  count++;
  if(count<11) return(0);   //the following code will be executed every 11 bars.
  txt=TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS)+txt; //the txt output also contains thee TimeCurrent().
  price=iHigh(Symbol(),Period(),0)+(iHigh(Symbol(),Period(),0)-iLow(Symbol(),Period(),0))/4;
  time=iTime(Symbol(),Period(),0);
  if(!ObjectCreate(objname, OBJ_TEXT, 0, time,price)) //I hope this can  output the txt object at the current bar.
    Print("Error:ObjectCreate failed: ",GetLastError());
  else Print(objname,"is created OK!!!!");
  if(!ObjectSetText(objname, txt, 14, "Arial", White)){
    Print("Error:ObjectSetText failed: ",GetLastError());
    obj++;
  }
  return(0);
}
//+------------------------------------------------------------------+

 


 
tzm:
Dear all, 
I have a problem on the output position of the text object. As shown in the code below, the text object will be out put with the text set to be "the time current."
But from the screenshot below, the timecurrent is "2012.09.10", But the text position is located around"2012.08.30".
..... The two "TIMES" are so different. May I know why? and how to display the text at the time(or the bar) when the ObjectCreate() function is called? Many thanks for your help.
You can't create an Object that already exists . . . check if the Object exists, ObjectFind(),  if it does then move it and change it's text,  use ObjectMove() or ObjectSet()  and ObjectSetText()
 
RaptorUK:
You can't create an Object that already exists . . . check if the Object exists, ObjectFind(),  if it does then move it and change it's text,  use ObjectMove() or ObjectSet()  and ObjectSetText()


Dear RaptorUK,

  Many thanks for your kind help.  I cannot access this website since last weekend. So i cannot reply to you promptly....

Reason: