Text problem

 

I have an issue with my indicator which I dont understand.

I have a makelabel function which is supposed to create a text by each bar with a number.

the alerts are just for my testing while trying to figure out this error

void makelabel(int index)
{string name,cnt,period;
  static int count=1;
//----
  period=DoubleToStr(oldperiod[index],0);
  cnt=DoubleToStr(count,0);
  name=StringConcatenate(id,"-",cnt);
  ObjectCreate(name,OBJ_TEXT,0,Time[index],moef[index]+5*Point);
  ObjectSetText(name,period,12,"Times New Roman",Red);
  Alert("makelabel index: ",index);
  Alert("Time= ",Time[index]);
  Alert("makelabel period = ",oldperiod[index]);
  count++;
//----
}

The issue is, when I attatch the indicator to a chart, the texts are not on the chart, but they are all in the objects list but they have a date of 1974 and have an erronous price co-ordinate.

But if I recompile this indicator while it is still attached to the chart, all the texts get the correct date and price values and they all appear on the chart.

The Alerts show the index is correct, it is the same as the bar number, and the array value is correct, the time is a timestamp it looks ok in that it is different for each index value except the zero index.

Can anyone tell me what am I missing ?

 
HAd same problems. Put WindowRedraw() at the end of Start(){}