MT4 Files Functions Replacement. - page 10

To add comments, please log in or register
Ingvar Engelbrecht
4431
Ingvar Engelbrecht  

File replacement

I want to test an EA that makes use of external signals in the Strategy Tester and the thread states that the native filehandling does not work in the strategy tester. So I have tried to use the dll supplied in this thread. The input I want to process is in a file looking like this:

2007-01-02;EURUSD;2.InstPipDown;;Yes

2007-01-02;USDJPY;1.InstPipUp;;Yes

2007-01-02;USDCHF;1.InstPipUp;;Yes

2007-01-03;EURUSD;2.InstPipDown;;Yes

2007-01-03;EURUSD;4.PipMax1Down;;Yes

2007-01-03;GBPUSD;4.PipMax1Down;;Yes

2007-01-04;USDJPY;8.PipRevBear;;Yes

2007-01-05;EURUSD;5.PipMax2Up;;Yes

2007-01-05;USDJPY;1.InstPipUp;;Yes

I do create the file myself so I can use other types of delimiters.

How do I use the dll to get one "record" at the time? I can do the parsing for the individual fields.

How do I know when I have reached EOF?

I have tried a few variations but I get inconsistent results and sometimes garbage. Writing data as in the example works fine but I want to read data.

Ingvar Engelbrecht
4431
Ingvar Engelbrecht  

Well, perserverance rules!

After several hours I found out this:

The file handler refuses to open a file I have created with another program. Open returns -1. If I use the file that was created by the demo (mt4.log) and copies my content into it open works. Cant figure out why. Strange

I made my "records" fixed length and read the length of the "record" plus 2 to accomodate for "CRLF" at the end of each record. I got the length of the file, divided by the record length and looped to get all my records into an array:

Here is the code:

int init()

{

string inArr[500];

int file;

int filesize;

int records;

int i;

file = gFileOpen("c:\mt4.log",READ);

// Print(file);

filesize = gFileSize(file);

// Print(filesize);

records = filesize/25;

// Print(records);

for(i=1;i<=records;i++)

{

inArr = gFileRead(file,25);

}

gFileClose(file);

Print(inArr[filesize-1]); //Check the last one

return(0);

}

PriNova
110
PriNova  

indicator with fileoutput

hello traders and programmers.

i need help with a codesegemnt for a new indicator.

the indicator should be able to write a file with relevant information, but it should only write after open a new candle. not every tick.

how could this be done? what i try to do is, on every new candle write OHCL of the last 1000 bars to train a PNN. this should be done outside with RAPID-I.

and with some other informations to learn what the probability the close of a candle could be.

please help. would be a great project, but so simple things i'm to stupid (or lazy) to do :-)

PriNova

auto_free_elitecamper
221
auto_free_elitecamper  

datetime timeprev=0; before init()

and

if(timeprev==Time[0])

return(0);

timeprev=Time[0]; right underneath start()

and thats it.

PriNova
110
PriNova  

nice this was very fast reply.

thank you elitecamper

johnmcglaughlin
7
johnmcglaughlin  

Why was the move function removed from the library

CodersGuru,

I can not tell you how valuable you are to me, You deserve much of the praise I receive from my clients, since without you I would not be able to do my job in support of them.

Is there a reason that the Move function was not implemented as is referenced in your tutorial.

Thanks Very Much Again four your service

John McGlaughlin

gorgoroth
9
gorgoroth  

gFileRead

Hello,

Looking the source code of mtguru1.dll I'have found that gFileRead() function should not work. Am I Wrong ?

gFileRead() uses a local variable to store the string read from the file. When the function returns, it returns a pointer to that variable, but this pointer can be a valid one because the local variable pbuffer goes out of scope.

So, from a MQL4 EA, an instruction like this should crash :

string buffer = gFileRead( handle, 50 );

and if it works it's strange ...

P.S.: I've posted this in the wrong thread, before. https://www.mql5.com/en/forum/172885.

gorgoroth
9
gorgoroth  

Errata Corrige:

.... but this pointer can be a valid one ....

but this pointer CANNOT be a valid one

auto_free_quantem
93
auto_free_quantem  

Execute an exe file

Hi,

I want to do a simple thing (so I thought). I want to simply open (launch) an external program from an EA. (not in the EA)

So just for exampe purposes. Let us say I wanted to open Microsoft word when a certain thing happens in the EA.

I have doen this before but I cannot find the script, I have spent 2 hours searching the web. Next time I will save the code somewhere safe!

Sixsense
37
Sixsense  

some question?

I got this error "2008.10.21 01:54:34 Fundamental Trader DailyFX_MQL4 v0.02: handle 2 does not exist in FileClose"

How can I do ?

To add comments, please log in or register