hi..guys.... i created an indicator with values from the total profit of the opened orders....whenever i restart the platform or refresh the screen, the data gets lost....how do i make the data persistent??..
- 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
Write the data to a file . . . read the stored data from said file . . . . or alternatively use GlobalVariables they are persistent for 4 weeks.
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.
hi heelflip43, ur code paste helped me a lot, but now only the very first value is getting read, how do i make the indicator take up all values and use it??
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