Try to use FileSeek() , for example:
//------------------------------------------------------------------------------ int i,m,n,r,s,u,v; double indA; int PeriodMM=11; int ModeMM=MODE_LWMA; int PriceMM=PRICE_WEIGHTED; //------------------------------------------------------------------------------ // SCRIPT start function | //------------------------------------------------------------------------------ int start() { int CntBars=Bars; int Mode,Price,CntBO=0,sumVolat=0,hfile; string filename="BarS1.txt"; double delta=0; FileDelete(filename); hfile=FileOpen(filename,FILE_READ|FILE_WRITE,"\t"); if(hfile<0) { Print(filename," OPEN Error: ",GetLastError()); return(0); } else FileSeek(hfile,SEEK_END,0); /*FileWrite(hfile,"Paire","Mode","Price","BarOut[%]", "DisM[Pi]","All","VolatM[Pi]");*/ for (i=0;i<CntBars;i++) {sumVolat+=High[i]-Low[i];} // for (Mode=0;Mode<4;Mode++) { for (Price=0;Price<7;Price++) { for (i=0;i<CntBars;i++) { indA=iMA(NULL,0,PeriodMM,0,Mode,Price,i); if (High[i]<indA) {CntBO++;delta+=(indA-High[i])/Point;} if (indA<Low[i]) {CntBO++; delta+= (Low[i]-indA)/Point;} } FileWrite(hfile,Symbol(),Mode,Price,100*CntBO/CntBars, delta/CntBO,delta/CntBars,sumVolat/CntBars); CntBO=0;delta=0; } } FileClose(hfile); return(0); } //------------------------------------------------------------------------------

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE.
So I use
hfile=FileOpen(filename,FILE_READ|FILE_WRITE,"\t");
to add data to the existing file.
But, if I re-launch my script, the previous data in the file (BarS1.txt) are lost.
What's wrong in my script?
How to keep previous data if I re-launch the script?
Do you have an idea?
Thanks.
CntBarOut.mq4