Yashar Seyyedin #:
My take is FileWriteStruct only works if the struct has native C++ types as fields.(long, int, double,...) MqlRates has a datetime field which is not a native type. That is why it is not working.
Sorry but that doesn't make sense. Of course datetime as a native type, as documented the only type restriction is "The structure should not contain strings, dynamic arrays or virtual functions."
My take is FileWriteStruct only works if the struct has native C++ types as fields.(long, int, double,...) MqlRates has a datetime field which is not a native type. That is why it is not working.
Don Baechtel:
THANKS.
What am I doing wrong?
int file_handle=FileOpen(InpDirectoryName+"//"+InpFileName,FILE_READ|FILE_WRITE|FILE_CSV|FILE_ANSI|FILE_TXT, ',');
Please read the documentation before posting.
FileWriteStruct
The function writes into a bin-file contents of a structure passed as a parameter, starting from the current position of the file pointer.
Incidentally a file can have 1 type ONLY, it's either CSV or TXT or BIN but not both at the same time.
You didn't specify what InpDirectoryNane is, not wheither it is a subdirectory of «DataFolder».

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
My EA has the following function:
The array mc,DIRI has 10 element with FOREX pair symbols in each element. The for statement iterates through each one.
For each symbol, it FileOpen a CSV output file for FILE_WRITE.
It executes CopyRaies for each symbol into the structure MqlRates Rates[].
There are 3 FileWrite statements that begin to write the first 3 rows from the Rates[]. This demonstraes that the Rates[] has good data in it.
The FileWriteStruct(file_handle, Rates[0]) statement should write the entire first row of data from Rates[0], but it generates no file output.
Each csv file only has 3 lines in it that look like:
2023.01.02 07:00:00,1.07016
2023.01.02 07:15:00,1.06969
2023.01.02 07:30:00,1.06929
Excel recognses the files as 3 rows of good CSV data.
Why does the FileWriteStruct generate no file output while the 3 FileWrite statements work OK.
I would like to save effort by using FileWriteStruct statement instead.
THANKS.
What am I doing wrong?