Try this:
//+------------------------------------------------------------------+ //| FileFunctionTest.mq4 | //| | //+------------------------------------------------------------------+ #include <stdlib.mqh> #property copyright "Copyright 2009 under Creative Commons BY-SA License by Neil D. Rosenthal" #property link "http://creativecommons.org/licenses/by-sa/3.0/" int FileHandle; string FileName; int FileMode; int UnitCount = 5; double Unit1_Size = 0.1; double Unit2_Size = 0.1; double Unit3_Size = 0.1; double Unit4_Size = 0.2; double Unit5_Size = 0.3; double TargetPrice1 = 1.47952; double TargetPrice2 = 1.47986; double TargetPrice3 = 1.48842; double TargetPrice4 = 1.48931; double TargetPrice5 = 1.49075; double PriceTarget1; double PriceTarget2; double PriceTarget3; double PriceTarget4; double PriceTarget5; int CountUnit; double UnitSize1; double UnitSize2; double UnitSize3; double UnitSize4; double UnitSize5; //---- int start() { //---- FileName = Symbol() + " Trade Data.csv"; FileHandle = FileOpen(FileName,FILE_CSV|FILE_WRITE,','); if(FileHandle > 0) { FileWrite(FileHandle,UnitCount); //FileFlush(FileHandle); FileWrite(FileHandle,Unit1_Size,Unit2_Size,Unit3_Size,Unit4_Size,Unit5_Size); //FileFlush(FileHandle); FileWrite(FileHandle,TargetPrice1,TargetPrice2,TargetPrice3,TargetPrice4,TargetPrice5); FileClose(FileHandle); } //end if(FileHandle > 0) FileHandle = FileOpen(FileName,FILE_CSV|FILE_READ,','); if(FileHandle > 0) { //while(!FileIsEnding(FileHandle)) //{ CountUnit = FileReadNumber(FileHandle); //FileFlush(FileHandle); UnitSize1 = FileReadNumber(FileHandle); //FileFlush(FileHandle); UnitSize2 = FileReadNumber(FileHandle); //FileFlush(FileHandle); UnitSize3 = FileReadNumber(FileHandle); //FileFlush(FileHandle); UnitSize4 = FileReadNumber(FileHandle); //FileFlush(FileHandle); UnitSize5 = FileReadNumber(FileHandle); //FileFlush(FileHandle); PriceTarget1 = FileReadNumber(FileHandle); //FileFlush(FileHandle); PriceTarget2 = FileReadNumber(FileHandle); //FileFlush(FileHandle); PriceTarget3 = FileReadNumber(FileHandle); //FileFlush(FileHandle); PriceTarget4 = FileReadNumber(FileHandle); //FileFlush(FileHandle); PriceTarget5 = FileReadNumber(FileHandle); //FileFlush(FileHandle); //end while(!FileIsEnding(FileHandle)) FileClose(FileHandle); } //end if(FileHandle > 0) Alert("CountUnit = " + CountUnit + "\nUnitSize1 = " + UnitSize1 + "\nUnitSize2 = " + UnitSize2 + "\nUnitSize3 = " + UnitSize3 + "\nUnitSize4 = " + UnitSize4 + "\nUnitSize5 = " + UnitSize5 + "\nPriceTarget1 = " + PriceTarget1 + "\nPriceTarget2 = " + PriceTarget2 + "\nPriceTarget3 = " + PriceTarget3 + "\nPriceTarget4 = " + PriceTarget4 + "\nPriceTarget5 = " + PriceTarget5); // //---- return(0); }

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 wrote a small script to learn how to use FileRead and FileWrite. FileWrite works OK, becauseI can open the resulting CSV file in NotePad to see the data. The problem is reading the data back into MT4. The script has an Alert in it so I can immediately visualize the data read back in. Only some of the data is read in correctly (see Alert box image following the code). As can be seen in the code, I have numerous FileFlush() commands commented out, as I experimented with number & placement of this command trying to get some output. I seem to be half-way there, but I can only get the first 6 numbers read back in, the last 5 numbers don't read in properly.
Here is the code, following the code is a screen shot of the Alert box and the data from the CSV file.
Here is the data from the CSV file:
Please help! Thanks!