FileReadArray() HELP!!!!

 

Hello! Hope you can help me out.

I have a file named "sample.bin" in the MQL4/Files directory that has the exact following content:

1
0
1
1
0
1


I want to create an array that has all of those 6 lines as array values.

The desired output is

array[1]=1      // (as per the first line of the sample.bin file)

array[2]=0     // (as per the second line of the sample.bin file)

array[3]=1      // (as per the third line of the sample.bin file)

array[4]=1      //etc

array[5]=0     //etc

array[6]=1

I tried the FileReadArray(); function but it keeps giving wrong values.

Ive attached the mq4 EA that I'm using so you can see the exact code I'm trying. However, it does not let me attach the .bin file "sample.bin" in this post. However, its just the exact values that I have posted above in this question.


I tried restructuring the sample.bin file to be

array[0]=1
array[1]=0
array[2]=1
array[3]=1
array[4]=0
array[5]=1

Then I tried again with those values in that file to see if maybe it has to do with how it "reads the array" in the file. However, it still gives the garbled "124564757" type numbers (maybe some type of code that needs an appropriate code page in the file open function?) in the actual array values in the EA. Whats going on? Been trying everything. I even tried the Code Pages to see if they had to do with it to no avail. You have any insight about this situation? Of note is that its giving the 5004 Error on the GetLastError(), which implies that its having problems opening the file,however only after it successfully opens it. This seems normal.

How do you add every line of the file into an array? Any easier way? Thanks in advanced!

Files:
 
Why not just use a bitfield and write one integer? 
 
nicholishen:
Why not just use a bitfield and write one integer? 

Sounds great; however how would you go about it? Googling MT4/mql bitfield didn't reveal much.


What exactly do you mean by "just use a bitfield"?

 
nadiawicket:

Hello! Hope you can help me out.

I have a file named "sample.bin" in the MQL4/Files directory that has the exact following content:

1
0
1
1
0
1


I want to create an array that has all of those 6 lines as array values.

The desired output is

array[1]=1      // (as per the first line of the sample.bin file)

array[2]=0     // (as per the second line of the sample.bin file)

array[3]=1      // (as per the third line of the sample.bin file)

array[4]=1      //etc

array[5]=0     //etc

array[6]=1

I tried the FileReadArray(); function but it keeps giving wrong values.

Ive attached the mq4 EA that I'm using so you can see the exact code I'm trying. However, it does not let me attach the .bin file "sample.bin" in this post. However, its just the exact values that I have posted above in this question.


I tried restructuring the sample.bin file to be

array[0]=1
array[1]=0
array[2]=1
array[3]=1
array[4]=0
array[5]=1

Then I tried again with those values in that file to see if maybe it has to do with how it "reads the array" in the file. However, it still gives the garbled "124564757" type numbers (maybe some type of code that needs an appropriate code page in the file open function?) in the actual array values in the EA. Whats going on? Been trying everything. I even tried the Code Pages to see if they had to do with it to no avail. You have any insight about this situation? Of note is that its giving the 5004 Error on the GetLastError(), which implies that its having problems opening the file,however only after it successfully opens it. This seems normal.

How do you add every line of the file into an array? Any easier way? Thanks in advanced!

You can not use FileReadArray() on that file (it was not created by using FileWriteArray())

Use FileWriteArray() to save data and then it will work. Something like this :

      int _array[] = {1,0,1,1,0,1}; 
      int _arrayFileHandle = FileOpen("sampleFile.sav",FILE_WRITE|FILE_BIN);
      if (_arrayFileHandle!=INVALID_HANDLE)
            { FileWriteArray(_arrayFileHandle,_array); FileClose(_arrayFileHandle);
              FileOpen("sampleFile.sav",FILE_READ|FILE_BIN); FileReadArray(_arrayFileHandle,_array); FileClose(_arrayFileHandle);
                                       Comment((string)_array[0]+"\n"+
                                               (string)_array[1]+"\n"+
                                               (string)_array[2]+"\n"+
                                               (string)_array[3]+"\n"+
                                               (string)_array[4]+"\n"+
                                               (string)_array[5]); }
or whatever type of data you want to use instead of using int for the array
 

Ничего не получится, для этого вам нужен переделанный период конвертер.

Его можно переделать в советник и добавить те функции которые я сделал в индикаторе. И тогда вы получите оффлайн график который будет постоянно обновляться

 
一条版主给您的信号 "SupjackFund"的新评论:

一条版主评论已经添加到您的信号 "SupjackFund"。评论仅提供给您和版主, 如有必要, 请阅读后给予回复.

要阅读评论,请点击 https://www.mql5.com/zh/signals/376092/edit#!tab=moderator

 
 
Market: You have activated the product News Robot MT4, 7 of 10 activations left. (See Rules, IV.10 and IV.11)
 

Happy to report a working solution:

   FileOpen("sample.csv",FILE_READ);
   
   array[1]=(FileReadString(1));
   array[2]=(FileReadString(1));
   array[3]=(FileReadString(1));
   array[4]=(FileReadString(1));
   array[5]=(FileReadString(1));
   array[6]=(FileReadString(1));
   
////   
   Alert("array 1 = ",array[1]);
   Alert("array 2 = ",array[2]);
   Alert("array 3 = ",array[3]);
   Alert("array 4 = ",array[4]);
   Alert("array 5 = ",array[5]);
   Alert("array 6 = ",array[6]);

This seems to work.

 
whroeder1:

What do I have to do to the sample file beforehand in order to have FileReadArray() read its contents correctly? Is there a way at all?

Reason: