store profit value to be used as an indicator .....
- Indicators: Two iMA Formula
- my code and ordersend dont work! please help me.
- Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes
hi dude.....i did as u said...but it keeps on creating a new file instead of appending values to it....the following s the code snippet....i suppose FILE_READ|FILE_WRITE should open the file in append mode, but it doesn't...what might be the prob??
handle=FileOpen("profit.txt", FILE_READ|FILE_WRITE)
To append values you need to skip to the end of the file by using SEEK_END as the origin and 0 as the offset.
handle=FileOpen("profit.txt", FILE_READ|FILE_WRITE); FileSeek(handle, 0, SEEK_END); // Free to write data at end of file string str = "Insert info here"; FileWriteString(handle, str, StringLen(str));
What your doing is just opening the file and writing straight to it. The other way is to loop through all the lines of data:
handle=FileOpen("profit.txt", FILE_READ|FILE_WRITE); while(!FileIsEnding(handle)) { string str = FileReadString(handle); // Do stuff with information } // File pointer is now at end so any FileWrite's will add to end of file str = "To be added"; FileWriteString(handle, str, StringLen(str));
Now I use FileWriteString here but you can use the others as well, I just tend to use strings for files. Either method will add data to the end of a file.