_lwrite: add new record in the end

 

Hello guys,
i used the function in object for have this result:

StopLoss_MR=20.00000000
StopLoss_MR,F=1
StopLoss_MR,1=20.00000000
StopLoss_MR,2=1.00000000
StopLoss_MR,3=25.00000000
but i have this:
StopLoss_MR=20.00000000StopLoss_MR,F=1StopLoss_MR,1=20.00000000StopLoss_MR,2=1.00000000StopLoss_MR,3=25.00000000

I do not know where is the problem, this is the code:

   string path=PathTester_set+File_set;
    int result;
    int handle=_lopen (path,OF_READWRITE|OF_SHARE_COMPAT);
    if(handle<0) 
      {
        handle=_lcreat (path,0);
        if(handle<0) 
          {
            Print ("Error creating file ",path);
            return;
          }
        result=_lclose (handle);
     }
    handle=_lopen (path,OF_READWRITE|OF_SHARE_COMPAT  );               
    if(handle<0) 
      {
        Print("Error opening file ",path); 
        return;
      }
    result=_llseek (handle,0,SEEK_END);          
    if(result<0) 
      {
        Print("Error placing pointer"); 
        return;
      }

for(int cnt=1; cnt<ArraySize(ArrayOpttim); cnt++) 
{ 
    result=_lwrite(handle,ArrayOpttim[cnt],StringLen(ArrayOpttim[cnt])) ; 
    if(result<0)  
        Print("Error writing to file ");
}    
    
    result=_lclose (handle);  //Print ("RESULT",result);            
    if(result<0)  
        Print("Error closing file ",path);  

Please, give me a advice.

thank's

 
  1. StopLoss_MR=20.00000000
    StopLoss_MR,F=1
    StopLoss_MR,1=20.00000000
    StopLoss_MR,2=1.00000000
    StopLoss_MR,3=25.00000000

    This show that in the optimizer you specified that the external variable StopLoss_MR should range from 20 to 25 in steps of one. The remainder code you posted does not reference the variable in question.


  2. I do not know where is the problem, this is the code:
    You do not specify a problem - there are no mind readers here.
  3. int handle=_lopen (path,OF_READWRITE|OF_SHARE_COMPAT);
        if(handle<0) ...
        handle=_lopen (path,OF_READWRITE|OF_SHARE_COMPAT  );  
    Why are you opening the file twice (if it succeeds) and losing the original handle?
 

With the function FileOpen/FileWrite/ FileClose, i have the desired result:

nas=0 ; a=0; b=0;  c=11;  MAX=c+1; ki=1;
  for(a = 0; a<1;a++)
   {
      for(b = 0; b<=0;b++)
      {
         for(c = 11; c<=12;c++) //MAX
         { 
            File_set=Currency_data[a]+"_"+Strategy_data[b]+"_"+DoubleToStr(c,0)+".set";
            string Strategy = StringSubstr (File_set,7,2); Print ("Strategy1",Strategy);
            if (Last_Strategy != Strategy){Import_var_set (Strategy);}
            Last_Strategy=Strategy;
            //MAX=ArraySize(PER);
            // SCRITTURA Set
            Print ("Val.std[ki]",PER[ki]+"-"+Val.std[ki]+"-"+Val.step[ki]);
            ArrayOpttim[1] = PER[ki]+"="+Val.std[ki];          
            ArrayOpttim[2] = PER[ki]+",F=1";                       
            ArrayOpttim[3] = PER[ki]+",1="+DoubleToStr(StrToDouble(Val.std[ki])-(StrToDouble(Val.std[ki])*Perc.aum.var),8);                       
            ArrayOpttim[4] = PER[ki]+",2="+Val.step[ki];                              
            ArrayOpttim[5] = PER[ki]+",3="+DoubleToStr(StrToDouble(Val.std[ki])+(StrToDouble(Val.std[ki])*Perc.aum.var),8);                       
             ki++;
            //------------------------------- Write data into the set file           --------------------------                 
            handle=FileOpen(File_set,FILE_CSV|FILE_WRITE|FILE_READ,';');     //Open a file to write
            FileSeek(handle,0,SEEK_END);
            for(int cnt=1; cnt<=ArraySize(ArrayOpttim); cnt++) FileWrite(handle,ArrayOpttim[cnt]); //20=arraysize(ArrayOptim)
            FileClose(handle);  
         }
      }
   }
StopLoss_MR=20.00000000
StopLoss_MR,F=1
StopLoss_MR,1=5.00000000
StopLoss_MR,2=1.00000000
StopLoss_MR,3=35.00000000

But i need to save the file in to another folder (expert / files) and with the function _lread/_lwrite/_lclose:

nas=0 ; a=0; b=0;  c=11;  MAX=c+1; ki=1;
  for(a = 0; a<1;a++)
   {
      for(b = 0; b<=0;b++)
      {
         for(c = 11; c<=12;c++) //MAX
         { 
            File_set=Currency_data[a]+"_"+Strategy_data[b]+"_"+DoubleToStr(c,0)+".set";
            string Strategy = StringSubstr (File_set,7,2); Print ("Strategy1",Strategy);
            if (Last_Strategy != Strategy){Import_var_set (Strategy);}
            Last_Strategy=Strategy;
            //MAX=ArraySize(PER);
            // SCRITTURA Set
            Print ("Val.std[ki]",PER[ki]+"-"+Val.std[ki]+"-"+Val.step[ki]);
            ArrayOpttim[1] = PER[ki]+"="+Val.std[ki];          
            ArrayOpttim[2] = PER[ki]+",F=1";                       
            ArrayOpttim[3] = PER[ki]+",1="+DoubleToStr(StrToDouble(Val.std[ki])-(StrToDouble(Val.std[ki])*Perc.aum.var),8);                       
            ArrayOpttim[4] = PER[ki]+",2="+Val.step[ki];                              
            ArrayOpttim[5] = PER[ki]+",3="+DoubleToStr(StrToDouble(Val.std[ki])+(StrToDouble(Val.std[ki])*Perc.aum.var),8);                       
             ki++;
            //------------------------------- Write data into the set file           --------------------------                 
         

int count=StringLen (buffer); 
string path=PathTester_set+File_set;
int result;
int handle=_lopen (path,OF_READWRITE|OF_SHARE_COMPAT);
if(handle<0) 
  {
    handle=_lcreat (path,0);
    if(handle<0) 
     {
        Print ("Error creating file ",path);
        return;
     }
       // result=_lclose (handle);
    // }
    //handle=_lopen (path,OF_READWRITE|OF_SHARE_COMPAT  );               
    //if(handle<0) 
    //  {
    //    Print("Error opening file ",path); 
    //    return;
    //  }
 result=_llseek (handle,0,SEEK_END);          
 if(result<0) 
   {
    Print("Error placing pointer"); 
     return;
   }

for(int cnt=1; cnt<ArraySize(ArrayOpttim); cnt++) 
{ 
   result=_lwrite(handle,ArrayOpttim[cnt],StringLen(ArrayOpttim[cnt])) ; 
   if(result<0)  
        Print("Error writing to file ");
}    
    
   result=_lclose (handle);  //Print ("RESULT",result);            
   if(result<0)  
        Print("Error closing file ",path);  

         }
      }
   }

and i have this result:

StopLoss_MR=0StopLoss_MR,F=1StopLoss_MR,1=5.00000000
WHRoeder, thank's for your time.