for(int cnt=0;cnt<=OrdersTotal();cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
Check your return codes What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles- There are OrdersTotal tickets, numbered zero to total - 1. The last OrderSelect will always fail.
- You must count down when closing/deleting/modifying in a position loop. Get in the habit of always counting down. Loops and Closing or Deleting Orders - MQL4 forum
- Using OrdersTotal directly and/or no Magic number filtering on your
OrderSelect loop means your code is incompatible with every EA (including
itself on other charts and manual trading.) Symbol Doesn't equal
Ordersymbol when another currency is added to another seperate chart . - MQL4
forum
int handle_1=FileOpen("Prova.txt", FILE_TXT|FILE_READ|FILE_WRITE, ';');
Why are you opening the file for writing in your recovery code?if(handle_1>0) { if (OrderSymbol()=="1st field" && OrderType()=="2nd field" && OrderOpenTime()=="4th field")
You haven't read the line out of the file. Read the columns into variables, then test if the symbol, etc matches.
I don't use the mt4/5 csv-reading functions - too heavy to handle:
int hdl = FileOpen(fName,FILE_READ|FILE_WRITE|FILE_BIN|FILE_COMMON); ... int nL,nC,c,i,sz = (int)FileSize(hdl); string lines[],cell[],all = FileReadString(hdl,sz); nL = i = StringSplit(all,StringGetCharacter("\n",0);,lines); while(i-->0) { nI = c = StringSplit(lines[i],StringGetCharacter(";",0),cell); int x = (int)StringToInteger(cell[0]); if (..) { lines[i] = ".."; //re-write (only) this line ... } FileSeek(hdl,0,SEEK_SET); // re-write all lines incl. the re-written one for(i=0;i<nL;i++) { sz = StringLen(lines[i]+"\n"); if (sz<10) continue; // skip empty lines FileWriteString(hdl,lines[i]+"\n",sz); //add the \n which was eliminated by the split } FileClose(hdl);(Without checking errors!)

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
Hi all, I made the attached .txt file using the following code
Now, I need to read these file at the start of a new week for the opened orders, when the Global Variables are resetted (because I shut down my VPS during the weekend).
First of all I recall the opened orders.
Then I need to assign the fields of the corresponding raw to the Global Variables: here I need an help.
Thank you very much!