Is there any limit on how many variables you can use in one EA? - page 2

tesforex
39
tesforex  
RaptorUK:

If that is you experience then you are doing something very wrong.

Well, can you be more specific?

William Roeder
25046
William Roeder  
tesforex: Well, can you be more specific?

How can we be more specific when we haven't seen all your code. No mind readers here.

But what you posted is wrong

FileOpen(File_Name, FILE_CSV|FILE_READ, ",");
The third argument to fileOpen is an int, NOT a string. Use ',' NOT ",".
Simon Gniadkowski
17391
Simon Gniadkowski  
tesforex:

Well, can you be more specific?

In my experience file functions work just fine within the Strategy tester,
tesforex
39
tesforex  
RaptorUK:

If that is you experience then you are doing something very wrong.

Thanks a lot for the correction! You are experienced so I'd like to share more information with you. It seems the EA can read files in testing mode now. But it still cannot work properly.

Most funny thing is that the same EA works well in forward test with CitiFX demo account, but doesn't work well with HotForex demo account (variable in global scope lost values at new tick).

Now I modified the code to save all those long strings in a csv file first and then read them to the variables at a new tick. In one test, the EA works OK for some period and then it stopped working at all.

I can post the some code here:

strings are defined as variable in global scope:

string symbol, Comment4Order[], tickets2modify = "", Long2Buy = "", Short2Sell = "", Long2Close = "", Short2Close = "", Long2TempTrade = "", Short2TempTrade = "", Long2TempExit_NS = "", Short2TempExit_NS = "", Long2Close_NS = "", Short2Close_NS = "", Order2CloseNow = "";
int init()
{

.......

ReadPendingTrades(); // at the beginning of the EA

.......

if (UpdatePendingBook) UpdatePendingOrders(tickets2modify, Long2Buy, Short2Sell, Long2Close, Short2Close, Long2TempTrade, Short2TempTrade, Long2TempExit, Short2TempExit, Long2TempExit_NS, Short2TempExit_NS, Long2Close_NS, Short2Close_NS); // at the end of the EA

........

}

bool UpdatePendingOrders(string tickets2modify, string Long2Buy, string Short2Sell, string Long2Close, string Short2Close, string Long2TempTrade, string Short2TempTrade, string Long2TempExit, string Short2TempExit, string Long2TempExit_NS, string Short2TempExit_NS, string Long2Close_NS, string Short2Close_NS)
{
int Handle;
string File_Name;
File_Name = StringConcatenate(symbol,"_order2check.csv");
Handle = FileOpen(File_Name, FILE_CSV|FILE_WRITE, ',');
if (FileWrite(Handle, tickets2modify, Long2Buy, Short2Sell, Long2Close, Short2Close, Long2TempTrade, Short2TempTrade, Long2TempExit, Short2TempExit, Long2TempExit_NS, Short2TempExit_NS, Long2Close_NS, Short2Close_NS) >= 0)
{
UpdatePendingBook = false;
FileClose(Handle);
return(true);
}
else
{
FileClose(Handle);
return(false);
}
}

int ReadPendingTrades()
{
int Handle;
string File_Name;
File_Name = StringConcatenate(symbol,"_order2check.csv");
Handle = FileOpen(File_Name, FILE_CSV|FILE_READ, ',');
if (Handle < 0)
{
if(GetLastError()==4103)
Alert("No file named ",File_Name);
else Alert("Error while opening file ",File_Name);
return(0);
}
else
{
tickets2modify = FileReadString(Handle);
Long2Buy = FileReadString(Handle);
Short2Sell = FileReadString(Handle);
Long2Close = FileReadString(Handle);
Short2Close = FileReadString(Handle);
Long2TempTrade = FileReadString(Handle);
Short2TempTrade = FileReadString(Handle);
Long2TempExit = FileReadString(Handle);
Short2TempExit = FileReadString(Handle);
Long2TempExit_NS = FileReadString(Handle);
Short2TempExit_NS = FileReadString(Handle);
Long2Close_NS = FileReadString(Handle);
Short2Close_NS = FileReadString(Handle);

}

FileClose(Handle);
return(1);
}

This is what I got in the AUDUSD_ order2check.csv file when the EA stopped working:

,,,,5*0.98757&6*0.98757&7*0.98757&10*0.98757&14*0.98757&17*0.98757&28*0.98757,,29*70949*0.98657,,5*70949*0.98661&28*70979*0.98661&29*70949*0.98661,,,,

Looks like the file was not properly read after some time so some trades were not executed and left in the file. But no error was shown at all.

BTW, the trade execution part is completely tested and has no problem.

Attached is the equity curve. The EA suddendly stopped working because of the file reading operations.

tesforex
39
tesforex  

BTW, it seems I cannot upload a pic. Is that because I am too new?

Simon Gniadkowski
17391
Simon Gniadkowski  
tesforex:

BTW, it seems I cannot upload a pic. Is that because I am too new?

I don't think so, what type of file is the picture ?

I think what you see in your CSV file is what you have written to it. For example, there appears to be no strings for the first 5 parameters, is that correct ?

tesforex
39
tesforex  
RaptorUK:

I don't think so, what type of file is the picture ?

I think what you see in your CSV file is what you have written to it. For example, there appears to be no strings for the first 5 parameters, is that correct ?


The pic is a gif file. When I click add button, the pic link just disaapeared.

Yes, the csv file is right. Normally, all those strings are empty.

The first group (#5) of non-empty strings (5*0.98757&6*0.98757&7*0.98757&10*0.98757&14*0.98757&17*0.98757&28*0.98757) in the csv file is for all the short orders I need to close. If price gets lower, they will be closed and removed from the csv file.

The second group (#7) of non-empty strings (29*70949*0.98657) is for a short order I temprarily exited before and I need to enter again if the price gets higher than the listed price (0.98657). This also means when this was added to the csv file, the market price must had dropped below 0.98657. That means all those short orders listed above should have been closed already since their listed exit price is 0.98757 (much higher than 0.98657). This means at least the 5*0.98757&6*0.98757&7*0.98757&10*0.98757&14*0.98757&17*0.98757&28*0.98757 string was not read to Short2Close variable or those orders (with ticket #5, 6, 7, 10, 14, 17, 18) should have been closed already.

So the file-reading function is not working properly!

onewithzachy
1863
onewithzachy  

Please use SRC button to post code and use Image button to post images (2nd to the left of SRC button)

smoknfx
85
smoknfx  

just for fun, i generated a source file that contains ten thousand int variables.

it runs fine on my laptop.

Files:
test.mq4  164 kb
tesforex
39
tesforex  
smoknfx:

just for fun, i generated a source file that contains ten thousand int variables.

it runs fine on my laptop.


Yes, I never get any error message but the program just doesn't run properly - it didn't do what it's coded to do.