Please show your attempts (code). Without it we cannot know what you might be doing wrong or help you in what you are trying to do.
And please use the code button and tell us what language you are using (MQL4 or 5).
Please show your attempts (code). Without it we cannot know what you might be doing wrong or help you in what you are trying to do.
And please use the code button and tell us what language you are using (MQL4 or 5).
void Write_file() { double Profit = 0; double NewProfit =0 ; string filename = "bookedProfit.csv"; FileDelete(filename); int filehandle = FileOpen(filename,FILE_COMMON|FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI,","); if(filehandle != INVALID_HANDLE) { FileSeek(filehandle,0,SEEK_SET); for(int i=0 ; i<2 ; i++) { if(NewProfit !=Profit) { NewProfit = Profit; } FileWrite(filehandle,Symbol()+(string)Period(),NewProfit); } FileClose(filehandle); } else Print("Failed to open and write ",filename," due to ",GetLastError()); }
its in mql4, i want to remove previous profit and rewrite new amount
My suggestion is :
Everytime profit amount of a pair changes just write the whole file from scratch.
It is not possible to replace a line without rewritten the entire file from the beginning, because each line is of variable length.
Standard text files (e.g. CSV) have no fixed sized record structure, and cannot be easily modified.
If you want to have a file with shared random access to the data, then you have to use fixed sized record structure, preferably using binary format.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello friends
I have a bot that runs on several currency pairs
I want to save the profit amount of each currency pair in one line of a file
For example:
EURUSD 19.30
USDCAD 8.03
AUDCHF 13.37
whenever the profit amount changes, I want to find the previous line, correct its value, or delete it, and rewrite the new amount in it.
who can help me to do it?