Ian Tavener:
I created a function to rewrite my order history for the month of March to an existing file, but I only want it to rewrite if the OrderTicket() does not exist in the file. The first time I run it, it writes all March's orders to separate files based on strategy, and it works just fine. But when I run it again, it writes every order again. The line where I wrote Print(OrderTicket()," true"); prints out true for every ticket number, but then still writes??? EDIT: I tried including Print(GetLastError()) after the while loop, error code returns 0 error.
I think I found my fix: Not entirely sure why it works, but it does.
void Rewrite() { ResetLastError(); for(int i=OrdersHistoryTotal()-1;i>=0;i--) { if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue; if(!OurMagicNumber(OrderMagicNumber())) continue; if(TimeMonth(OrderOpenTime())<3) continue; int strat=(int)StringSubstr(OrderComment(),1,1); bool exist=false; FileSeek(filehandle_[strat],0,SEEK_SET); while(!FileIsEnding(filehandle_[strat]) && !IsStopped()) { string finder=FileReadString(filehandle_[strat]); if(finder!=(string)OrderTicket()) continue; else { exist=true; break; } } if(!exist) WriteTradeHistory(OrderTicket(),"rewrite"); } MakeMyTerminal("History Rewrite Complete"); }

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
I created a function to rewrite my order history for the month of March to an existing file, but I only want it to rewrite if the OrderTicket() does not exist in the file. The first time I run it, it writes all March's orders to separate files based on strategy, and it works just fine. But when I run it again, it writes every order again. The line where I wrote Print(OrderTicket()," true"); prints out true for every ticket number, but then still writes??? EDIT: I tried including Print(GetLastError()) after the while loop, error code returns 0 error.