While the documentation (see FileOpen()) shows the delimiter being enclosed in single quotation marks, the book (see File Operations) is inconsistent regarding the use of single quotation marks: some of the code examples show the use of the double quotation marks.
While the documentation (see FileOpen()) shows the delimiter being enclosed in single quotation marks, the book (see File Operations) is inconsistent regarding the use of single quotation marks: some of the code examples show the use of the double quotation marks.
Additionally, the following code:
compiled, did not have any runtime errors, and produced the following output in the file:
I tried ";" and ';' got the same problem.
My code runs and works great, the file is created and every tick the file is opened, all the info is written into it and then the file is closed. All works great until the EA opens an order, then nothing is written on the file.
WHRoeder: The first is a string, the second is an int (as required.) The error mentioned p 1. Multiple problems?
The error is the file handle, the handle is always 1 and always works, but when the EA opens an order, the next tick it says Handle is invalid even though it is 1 again and has worked for the last hundreds of ticks. The last time I tried it handle started going up when the order opened, it became 2, 3, 4, etc.
It's the exact same code, I don't know why it doesn't stay as 1, and even when it's still 1 it still gives the error.
I can't see an issue with the code you have posted.
So I see 2 options :
post all your code so we can try it for ourselves and try to fix it
create a short script/EA that replicates the issue and post that
Thank you RaptorUK, I had already created an EA that replicates the issue exactly to try and fix the problem. Basically it starts, it creates the file them each tick it writs on the file counting the ticks. So the file is like tick 1, tick 2, etc.
On tick 15 it opens an order, the order info appears in the file and the end (******) also appears. After that it's supposed to write in each tick the tick number (16, 17, etc) and the status of the order, meaning if the order is still opened or not. For some reason after tick 15 the EA doesn't write on the file.
At tick 50 it's supposed to close the order but that's not important, what's important is that it keeps writing on the file when it opens the order.
In my Windows 7 machine the files are created in C:\Users\{username}\AppData\Local\VirtualStore\Program Files (x86)\SIGTrader 4\experts\files
Appdata is a hidden folder.
Thanks in advance
Code:
//+------------------------------------------------------------------+//| log.mq4 |//| Copyright 2013, MetaQuotes Software Corp. |//| http://www.metaquotes.net |//+------------------------------------------------------------------+#property copyright "Copyright 2013, MetaQuotes Software Corp."#property link "http://www.metaquotes.net"externstring Nombre_archivo="log";
externint Take_Profit=6;
externint Stop_Loss=35;
externint Deslizamiento=4;
externdouble vol=1;
int Handle, Qnt_Symb, ticket, err, abierta = 0;
string File_Name, larcor;
int cont=1;
//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init()
{
//----
File_Name = StringConcatenate(Nombre_archivo, " - ", Symbol(), " - ", TimeToStr(TimeLocal(),TIME_DATE), " - ", TimeHour(TimeLocal()), ".", TimeMinute(TimeLocal()), ".", TimeSeconds(TimeLocal()), ".txt");
Handle=FileOpen(File_Name,FILE_CSV|FILE_WRITE,';');//File openingif(Handle==-1) // File opening fails
{
Alert("An error while opening the file. ",// Error message"May be the file is busy by the other applictiom");
PlaySound("Bzrrr.wav"); // Sound accompanimentreturn; // Exir start()
}
FileClose( Handle );
//----return(0);
}
//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit()
{
//----//----return(0);
}
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
//----double op, cl;
Print("Order open: ", abierta);
//Print("File: ", File_Name);
Handle=FileOpen(File_Name,FILE_CSV|FILE_READ|FILE_WRITE,';');//File openingPrint("Handle: ", Handle);
if(Handle==-1) // File opening fails
{
Alert("An error while opening the file. ",// Error message"May be the file is busy by the other applictiom");
PlaySound("Bzrrr.wav"); // Sound accompanimentreturn; // Exir start()
}
FileSeek(Handle, 0, SEEK_END);
Qnt_Symb=FileWrite(Handle,"**** INICIANDO TICK PAR ", Symbol(), ": ", TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS), " ****");
Qnt_Symb=FileWrite(Handle,"************************************************************");
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Este es el tick num: ", cont);
if(cont == 15){
op = iOpen(NULL, 0, 0);
cl = iClose(NULL, 0, 0);
if(op < cl){
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Estamos en LARGO, se abre compra");
ticket = OrderSend(Symbol(),OP_BUY,vol,Ask,Deslizamiento,Ask-Stop_Loss*Point,Ask+Take_Profit*Point);
if(ticket == -1){
err = GetLastError();
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - "," Error No. ", err, " al tratar de abrir la orden");
}
else{
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - "," Abierta orden ", ticket, ", hora: ", TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
abierta = 1;
}
}
else{
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Estamos en CORTO, se abre venta");
ticket = OrderSend(Symbol(),OP_SELL,vol,Bid,Deslizamiento,Bid+Stop_Loss*Point,Bid-Take_Profit*Point);
if(ticket == -1){
err = GetLastError();
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - "," Error No. ", err, " al tratar de abrir la orden");
}
else{
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - "," Abierta orden ", ticket, ", hora: ", TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
abierta = 1;
}
}
}
if((cont > 15) && (cont < 50)){
if(ticket != -1){
if(OrderSelect(ticket, SELECT_BY_TICKET) == true){
datetime horacierre = OrderCloseTime();
if(horacierre == 0){
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Orden ", ticket, " en par ". Symbol(), " sigue abierta.");
}
else{
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","La orden ", ticket, " se cerro automaticamente a las ", TimeToStr(horacierre,TIME_DATE|TIME_SECONDS));
}
}
}
}
if(cont == 50){
if(abierta == 1){
if(larcor == "LARGO"){
if(OrderClose(ticket,OrderLots(),Ask,3)){
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Se cerro la orden ", ticket, " en LARGO");
}
else{
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","No se pudo cerrar la orden ", ticket, " en LARGO");
}
}
else{
if(OrderClose(ticket,OrderLots(),Bid,3)){
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Se cerro la orden en CORTO");
}
else{
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","No se pudo cerrar la orden ", ticket, " en CORTO");
}
}
}
}
if(cont > 50){
Qnt_Symb=FileWrite(Handle,TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS)," - ","Fin de EA");
}
Qnt_Symb=FileWrite(Handle,"***************************");
Qnt_Symb=FileWrite(Handle,"**** FIN TICK PAR ", Symbol(), " ****");
FileClose( Handle );
cont++;
//----return(0);
}
//+------------------------------------------------------------------+
Thank you RaptorUK, I had already created an EA that replicates the issue exactly to try and fix the problem. Basically it starts, it creates the file them each tick it writs on the file counting the ticks. So the file is like tick 1, tick 2, etc.
On tick 15 it opens an order, the order info appears in the file and the end (******) also appears. After that it's supposed to write in each tick the tick number (16, 17, etc) and the status of the order, meaning if the order is still opened or not. For some reason after tick 15 the EA doesn't write on the file.
At tick 50 it's supposed to close the order but that's not important, what's important is that it keeps writing on the file when it opens the order.
In my Windows 7 machine the files are created in C:\Users\{username}\AppData\Local\VirtualStore\Program Files (x86)\SIGTrader 4\experts\files
Appdata is a hidden folder.
Thanks in advance
Code:
You code will not place trades with the Broker I use for testing, it's an ECN "type" Broker. I'll adjust and set the TP and SL to 0.0
WHRoeder:
Invalid last argument - not an int
Could you please elaborate on what you mean?
While the documentation (see FileOpen()) shows the delimiter being enclosed in single quotation marks, the book (see File Operations) is inconsistent regarding the use of single quotation marks: some of the code examples show the use of the double quotation marks.
Additionally, the following code:
compiled, did not have any runtime errors, and produced the following output in the file:
Sorry, "parts" . . . do you get the **** END TICK USDCHF **** message ? or does it end before that ?
Yes, the file is complete.
You have ";" not ';' . . . the error message you received talked about parameter 1, isn't that the file handle ?
Yes, someone else was talkin gabout invalid last parameter, I don't know why. Still I changed ";" for ';' but got the same problem.
Could you please elaborate on what you mean?
While the documentation (see FileOpen()) shows the delimiter being enclosed in single quotation marks, the book (see File Operations) is inconsistent regarding the use of single quotation marks: some of the code examples show the use of the double quotation marks.
Additionally, the following code:
compiled, did not have any runtime errors, and produced the following output in the file:
I tried ";" and ';' got the same problem.
My code runs and works great, the file is created and every tick the file is opened, all the info is written into it and then the file is closed. All works great until the EA opens an order, then nothing is written on the file.
The first is a string, the second is an int (as required.) The error mentioned p 1. Multiple problems?
The error is the file handle, the handle is always 1 and always works, but when the EA opens an order, the next tick it says Handle is invalid even though it is 1 again and has worked for the last hundreds of ticks. The last time I tried it handle started going up when the order opened, it became 2, 3, 4, etc.
It's the exact same code, I don't know why it doesn't stay as 1, and even when it's still 1 it still gives the error.
Any idea guys?
I can't see an issue with the code you have posted.
So I see 2 options :
I can't see an issue with the code you have posted.
So I see 2 options :
Thank you RaptorUK, I had already created an EA that replicates the issue exactly to try and fix the problem. Basically it starts, it creates the file them each tick it writs on the file counting the ticks. So the file is like tick 1, tick 2, etc.
On tick 15 it opens an order, the order info appears in the file and the end (******) also appears. After that it's supposed to write in each tick the tick number (16, 17, etc) and the status of the order, meaning if the order is still opened or not. For some reason after tick 15 the EA doesn't write on the file.
At tick 50 it's supposed to close the order but that's not important, what's important is that it keeps writing on the file when it opens the order.
In my Windows 7 machine the files are created in C:\Users\{username}\AppData\Local\VirtualStore\Program Files (x86)\SIGTrader 4\experts\files
Appdata is a hidden folder.
Thanks in advance
Code:
Thank you RaptorUK, I had already created an EA that replicates the issue exactly to try and fix the problem. Basically it starts, it creates the file them each tick it writs on the file counting the ticks. So the file is like tick 1, tick 2, etc.
On tick 15 it opens an order, the order info appears in the file and the end (******) also appears. After that it's supposed to write in each tick the tick number (16, 17, etc) and the status of the order, meaning if the order is still opened or not. For some reason after tick 15 the EA doesn't write on the file.
At tick 50 it's supposed to close the order but that's not important, what's important is that it keeps writing on the file when it opens the order.
In my Windows 7 machine the files are created in C:\Users\{username}\AppData\Local\VirtualStore\Program Files (x86)\SIGTrader 4\experts\files
Appdata is a hidden folder.
Thanks in advance
Code: