FileRead function

 

Hi, I'm writing an expert on M3 offline chart.

I need to recall a double from M3 offline chart. I'm trying with the following code but it doesn't work...

int handle;

double varray[1];

handle=FileOpen("EURUSDM2.hst", FILE_BIN|FILE_READ);
if(handle>0)
{
FileReadArray(handle, varray, 0, 0);
FileClose(handle);
}

My doubt is this: how can I recall low value of the last bar in the M2 chart?

Thank you!

 

Since you already have the M3 data, I'm going to assume that you already have a script which converts M1 data into M2.

From my understanding of .hst files, there is a header at the top of the file so what I think is happening is that currently your reading that header. Have a look at how your script writes the data and work backwards from there.

 
Alberto_jazz:

I need to recall a double from M3 offline chart. I'm trying with the following code but it doesn't work...


It would be helpful to say what doesn't work exactly. It would also be helpful to paste the code into the window after clicking the "SRC" button (for source code).

int handle;

double varray[5002];

handle=FileOpen("EURUSDM2.hst", FILE_BIN|FILE_READ);
if( handle>0 ){
   FileReadArray(handle, varray, 0, 5000);
   FileClose(handle);
}

You have asked it to read zero elements into the array so the above may now work.

 

I'm writing an expert (attached on M2 chart) in which I wrote:

int handle=FileOpen("EURUSD_Low_0.dat", FILE_BIN|FILE_WRITE);
int h1;
if(handle>0)
{
FileWriteDouble(h1,Low[0],DOUBLE_VALUE);
FileClose(handle);
handle=0;
} 

Then in M3 expert I wrote:

int handle=FileOpen("EURUSD_Low_0.dat",FILE_BIN);

if(handle>0)
{
LOW_0=FileReadDouble(handle,DOUBLE_VALUE);
FileClose(handle);
}

The problem is in the FileWriteDouble: I don't know what is the first input "h1" (from the help editor).

Thank you!

 

Please use this to post code . . . it makes it easier to read.

 

h1 is the handle, you have a variable already for that called . . handle

FileWriteDouble . . . . handle - File handle returned by the FileOpen() function.

 

Ok, now it works!

The only problem is that I'd using a 5 digit broker, but the Low[0] format is 4 digit. How can I obtain 5 digit? Thank you!

 
Alberto_jazz:

Ok, now it works!

The only problem is that I'd using a 5 digit broker, but the Low[0] format is 4 digit. How can I obtain 5 digit? Thank you!

What make you think it is 4 Digit only ? when you Print it is formatted to 4 digit . . . if you want to Print with 5 digits use DoubleToStr
 

This is the solution to my problem.

I attach an expert to M2 graph:

int handle=FileOpen("EURUSD_Low_0.dat", FILE_BIN|FILE_WRITE);

         if(handle>0)
           {
           FileWriteDouble(handle,Low[0],DOUBLE_VALUE);
           FileClose(handle);
           handle=0;
           }

Then in the expert attached on M3 graph I wrote:

int handle;

  handle=FileOpen("EURUSD_Low_0.dat",FILE_BIN);
   
  if(handle>0)
    {
     LOW_0=FileReadDouble(handle,DOUBLE_VALUE);
     FileClose(handle);
    }
Reason: