Refresh file info

To add comments, please log in or register
Yusepet
10
Yusepet  

Hi,

My Script download bars data  to a CSV file.

Everything it's fine.

If a drag and drop script into GBPUSD H4 my csv file has GBPUSD H4 data info.

But....

When I drag and drop my script into EURUSD H4, data downloaded in file  is still GBPUSD H4  data.

When I change file name and execute script to EURUSD, then, data downloaded is refreshed and is correct.

What it is the problem?? Why file is not refreshed every time i run script.

//+------------------------------------------------------------------+
//|   Calculo y rellenar fichero con parametros de trampas           |
//+------------------------------------------------------------------+
void calc_param_trampas()

 {
 
  int      vela_ini;
  int      vela_fin; 
  int      base_trampa; 
  int      altura_trampa; 
  int      rec_max_int; 
  int      stop_loss_trampa;
  int      year;
  int      mes;
  int      dia;
  int      hora;
  int      tipo_trampa;
  
  datetime time1;
  datetime time2;
  
  double   price1;
  double   price2;
  double   param_h;
  double   price_low;
  double   price_high; 
  
  string  Compra_Venta;
  
  
  int obj_total=ObjectsTotal();
  
  nom_fich="Test001.csv";
  
  ResetLastError(); 
  
  int handle=FileOpen(nom_fich,FILE_READ|FILE_WRITE|FILE_CSV,';');
   
  if (handle<0) 
     {
      Print("Error crear fichero");
       
      return;
     }   
     
     FileSeek(handle, 0, SEEK_END); 
         
 
     FileWrite(handle,"C_V;PAR;AÑO;MES;DIA;HORA;BASE;ALTURA;RECMAXIMO;STOP LOSS");     
 
     for(int i=0;i<obj_total;i++)
     {
       name = ObjectName(i);    
            
       string objeto_grf=StringSubstr(name,0,9);
       
       if (objeto_grf=="MC_Trampa")
       {
       
         time1=ObjectGet(name,OBJPROP_TIME1);
         time2=ObjectGet(name,OBJPROP_TIME2);
         vela_ini=iBarShift(NULL,0,time1);  
         vela_fin=iBarShift(NULL,0,time2);
                 
// La fecha la separo en Año/Mes/Dia

         year=TimeYear(time2);
                   mes=TimeMonth(time2);
                   dia=TimeDay(time2);
                   hora=TimeHour(time2);
        
//Calculo la base de la trampa
       
              base_trampa=calculo_base_trampa(vela_ini, vela_fin);
   
//Calculo Altura de la trampa  

         altura_trampa=calculo_altura_trampa(vela_ini, vela_fin);            
      
//Calculo Recorrido máximo 

         rec_max_int=calculo_recorrido_maximo(vela_ini, vela_fin);
      
//Calculo Stop Loss
         stop_loss_trampa=calculo_stop_loss(vela_ini,vela_fin);           
                 
// Tipo de Trampa
         tipo_trampa=tipo_de_trampa(vela_ini);
         
         if(tipo_trampa==1)
            {
             Compra_Venta="V";
            }
         else
            {
             Compra_Venta="C";
            }    
         
// Escribo registro     fichero  
    
         FileWrite(handle,Compra_Venta,Symbol(),year,mes,dia,hora,base_trampa,altura_trampa,rec_max_int,stop_loss_trampa);   
          
         FileFlush(handle);
 
         }
      }
      FileClose(handle);
      Print("FileClose hecho");   
      return; 
 } 

void calc_param_trampas is called in OnStart() 

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
    calc_param_trampas();
    return;      
  }
  

I'm a very Newbie.

My first Script.

Sorry my english.

Keith Watford
Moderator
17042
Keith Watford  
If you don't show the code, you are unlikely to get any suggestions.
William Roeder
18943
William Roeder  
Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.
William Roeder
18943
William Roeder  
Yusepet: When I drag and drop my script into EURUSD H4, data downloaded in file  is still GBPUSD H4  data.
  int handle=FileOpen(nom_fich,FILE_READ|FILE_WRITE|FILE_CSV,';');
⋮
     FileSeek(handle, 0, SEEK_END); 
You are appending to the file, why does it having the previous data surprise you?
To add comments, please log in or register