Funciona se eu plotar no grafico mas nao no teste

 
EU escrevi um codigo simples pra desenhar linhas de 
suporte e resistencia baseado em fractais, no grafico 
em tempo real funciona muito bem, mas nos testes as coordenadas 
pra criar a ltb e lta bugam e so atualiza um lado 

eu sei que o codigo precisa de muita verificação de 
erros na chamada das funcoes e muita otimização, 
mas como é so um estudo eu pretendo aperfeiçoar com o tempo, 
obrigado a quem puder ajudar





input color Resistance_Color=Red;
input ENUM_LINE_STYLE Resistance_Style;
input int Resistance_Width=1;
input color Support_Color=Red;
input ENUM_LINE_STYLE Support_Style;
input int Support_Width=1;

double fupbuffer[];
double flowbuffer[];
int fhandle;
int up_pos1,up_pos2,low_pos1,low_pos2;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   fhandle=iFractals(_Symbol,0);
   ArraySetAsSeries(flowbuffer,true);
   ArraySetAsSeries(fupbuffer,true);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int i;
   double up_price1[],up_price2[],low_price1[],low_price2[];
   
   ArrayResize(up_price1,1);
   ArrayResize(up_price2,1);
   ArrayResize(low_price1,1);
   ArrayResize(low_price2,1);
   

///ZERANDO BOOLEANAS DE OTIMIZAÇÃO====================================================   

//---COPIANDO OS BUFFERS==============================================================
   CopyBuffer(fhandle,0,0,Bars(_Symbol,0),fupbuffer);
   CopyBuffer(fhandle,1,0,Bars(_Symbol,0),flowbuffer);

/// ACHANDO FRACTAIS SUPERIORES ========================================================    
   for(i=0;i<Bars(_Symbol,0); i++)
     {
      if(fupbuffer[i]!=EMPTY_VALUE)break;
     }
   up_price1[0]=fupbuffer[i];
   up_pos1=i;

   for(i=up_pos1+1;i<Bars(_Symbol,0); i++)
     {
      if(fupbuffer[i]!=EMPTY_VALUE)break;
     }
   up_price2[0]=fupbuffer[i];
   up_pos2=i;
/// ACHANDO FRACTAIS INFERIORES ========================================================  
   for(i=0;i<Bars(_Symbol,0); i++)
     {
      if(flowbuffer[i]!=EMPTY_VALUE)break;
     }
   low_price1[0]=flowbuffer[i];
   low_pos1=i;

   for(i=low_pos1+1;i<Bars(_Symbol,0); i++)
     {
      if(flowbuffer[i]!=EMPTY_VALUE)break;
     }
   low_price2[0]=flowbuffer[i];
   low_pos2=i;
//// COPIANDO HORARIOS E DATAS=====================================================================  

   datetime up_time1[],up_time2[],low_time1[],low_time2[];

///DATAS E HORARIOS DOS FRACTAIS SUPERIORES====================================== 
   CopyTime(_Symbol,0,up_pos1,1,up_time1);
   CopyTime(_Symbol,0,up_pos2,1,up_time2);
///DATAS E HORARIOS DOS FRACTAIS INFERIORES====================================== 
   CopyTime(_Symbol,0,low_pos1,1,low_time1);
   CopyTime(_Symbol,0,low_pos2,1,low_time2);

   Print("UP PTICE:  ",up_price1[0],"  UP PRICE 2:  ",up_price2[0],"  LOW PRICE:  ",low_price1[0],"  LOW PRICE 2:  ",low_price2[0]);
   Print("UP POS 1:  ",up_pos1,"  UP POS 2:  ",up_pos2,"  LOW POS 1:  ",low_pos1,"  LOW POS 2:  ",low_pos2);

///CRIANDO LTA E LTB==================================================
   if(up_price1[0]<up_price2[0])
     {
      ObjectCreate(0,"ltb",OBJ_TREND,0,up_time2[0],up_price2[0],up_time1[0],up_price1[0]);
      ObjectSetInteger(0,"ltb",OBJPROP_RAY_RIGHT,true);
      ObjectSetInteger(0,"ltb",OBJPROP_COLOR,Support_Color);
      ObjectSetInteger(0,"ltb",OBJPROP_STYLE,Support_Style);
      ObjectSetInteger(0,"ltb",OBJPROP_WIDTH,Support_Width);
     }

   if(low_price1[0]>low_price2[0])
     {
      ObjectCreate(0,"lta",OBJ_TREND,0,low_time2[0],low_price2[0],low_time1[0],low_price1[0]);
      ObjectSetInteger(0,"lta",OBJPROP_RAY_RIGHT,true);
      ObjectSetInteger(0,"lta",OBJPROP_COLOR,Support_Color);
      ObjectSetInteger(0,"lta",OBJPROP_STYLE,Support_Style);
      ObjectSetInteger(0,"lta",OBJPROP_WIDTH,Support_Width);
     }

  }
 
 if(up_price1[0]<up_price2[0])
     {
      
      ObjectDelete(0,"ltb");
     
      ObjectCreate(0,"ltb",OBJ_TREND,0,up_time2[0],up_price2[0],up_time1[0],up_price1[0]);
      ObjectSetInteger(0,"ltb",OBJPROP_RAY_RIGHT,true);
      ObjectSetInteger(0,"ltb",OBJPROP_COLOR,Support_Color);
      ObjectSetInteger(0,"ltb",OBJPROP_STYLE,Support_Style);
      ObjectSetInteger(0,"ltb",OBJPROP_WIDTH,Support_Width);
     }

   if(low_price1[0]>low_price2[0])
     {
     
      ObjectDelete(0,"lta");
     
      ObjectCreate(0,"lta",OBJ_TREND,0,low_time2[0],low_price2[0],low_time1[0],low_price1[0]);
      ObjectSetInteger(0,"lta",OBJPROP_RAY_RIGHT,true);
      ObjectSetInteger(0,"lta",OBJPROP_COLOR,Support_Color);
      ObjectSetInteger(0,"lta",OBJPROP_STYLE,Support_Style);
      ObjectSetInteger(0,"lta",OBJPROP_WIDTH,Support_Width);
     }

  }

resolvi e vou botar aqui caso alguem tenha um problema parecido 


faltou deletar as ltas e ltbs antigas com o ObjectDelete isso deve ter dado algum problema na memoria e "travou" algumas coordenadas

 
pedro de: