ObjectCreate issue

 

Hi,


I have some code that removes all hlines from a chart then creates new lines. There seems to be an issue wherby after I've used ObjectsDeleteAll() and then create a hline object the function returns true but no line is created. If i remove the ObjectsDeleteAll() function before the lines are createde correctly. Any ideas?

Heres part of the code...

void OnStart()
  {
   long chartIds[];
   long chartId;  
   
   // ask user user if they want to keep or remove existing Hline objects
   int mBoxResult = MessageBox("Keep exisiting lines?","Draw line Objects",MB_YESNOCANCEL);
   
   if(GetChartIds(chartIds))
     {
      for(int i=ArraySize(chartIds)-1;i>=0;i--)
        {
         chartId=chartIds[i];
         string symbolName = ChartSymbol(chartId); 
         
         // declare array to store line structure
         lineData hLines[];

         // open and read file
         bool readResult = getSandR(chartId, hLines);
         
         //plot the chart objects
         if (readResult)
          {              
            if (mBoxResult != IDCANCEL)
             {
              if (mBoxResult == IDNO)
               {
                rmvAll_HlineObjects(chartId);
               }
            
              bool plotResult = plotHLine(chartId, hLines);
             }
           }
        }
     }
   return;
  } 

bool plotHLine(long chartId, lineData &hLines[])
  {
   // get number of lines
   int objTot = ArraySize(hLines);
   for (int iObj=0;iObj<objTot;iObj++)
   {
      datetime timeNow = TimeCurrent();
      string objName = string(timeNow) + string(MathRand());
      
      //create new object
      bool cmdSent = ObjectCreate(chartId,objName,OBJ_HLINE,0,Time[0],hLines[iObj].price);
      bool found = ObjectFind(chartId,objName);
      Alert("create cmd sent=",cmdSent,"Obj Found? = ",found);
      ObjectSetInteger(chartId,objName,OBJPROP_STYLE,hLines[iObj].style);
      ObjectSetInteger(chartId,objName,OBJPROP_WIDTH,hLines[iObj].width);
      ObjectSetInteger(chartId,objName,OBJPROP_COLOR,hLines[iObj].col);
      //ObjectSetDouble(chartId,objName,OBJPROP_PRICE,hLines[iObj].price);
      
      //set line to ray style
      ObjectSetInteger(chartId,objName,OBJPROP_RAY,true);
   }
   return true;
  }


  void rmvAll_HlineObjects(long chartId)
   { 
    Alert("Delete Objects on chartID=",chartId);
    ObjectsDeleteAll(chartId,0,OBJ_HLINE);
   }
Reason: