Hi,
I'm trying to save active orders (Tickets) OnDeinit() into a binary file but is not working. (Note: The handle is created but the file is left blank.)
Can anybody tell me why? Here is the piece of code:
for (int i = 1; i < activeOrders; i++) will not catch the first order ... for (int i=0;i<activeOrders;i++)
But better will be otherwise i=activeorders-1;i>=0;i--
FileSeek after FileWrite you dont need...
for (int i = 1; i < activeOrders; i++) will not catch the first order ... for (int i=0;i<activeOrders;i++)
But better will be otherwise i=activeorders-1;i>=0;i--
FileSeek after FileWrite you dont need...
let me try and see if it works...
P.S. Still, this fix is not writing to file either.
I'm trying to save active orders (Tickets) OnDeinit() into a binary file but is not working. [...]
[..] if you save the list as a text file, e.g. with each ticket number on a separate line. [..]
Would you show me a brief example, please!
You can just get MT4 to read and write the list as a CSV file which only happens to have one entry per line. For example, you can write the file as follows:
int f = FileOpen("test.txt", FILE_CSV | FILE_WRITE); FileWrite(f, 123); FileWrite(f, 456); FileWrite(f, 789); FileClose(f);
You then read it back in as though it was a CSV file:
int f = FileOpen("test.txt", FILE_CSV | FILE_READ); while (!FileIsEnding(f)) { int Ticket = FileReadNumber(f); Print("Read: " + Ticket); } FileClose(f);
The only complication is that MT4 reads an extra entry (with Ticket == 0). You can either watch for this and ignore it, or you can use code such as the following which explicitly checks for blank lines:
int f = FileOpen("test.txt", FILE_CSV | FILE_READ); while (!FileIsEnding(f)) { string strLine = FileReadString(f); if (strLine != "") { int Ticket = StrToInteger(strLine); Print("Read: " + Ticket); } } FileClose(f);
[...]
Thanks so much.. appreciated! Will try!
Problem is FIXED. The cause was the size of the file name apparently: robotorders.bin(BAD: too long?!), orders.bin(GOOD!)
THX 2 ALL!!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I'm trying to save active orders (Tickets) OnDeinit() into a binary file but is not working. (Note: The handle is created but the file is left blank.)
Can anybody tell me why? Here is the piece of code: