There isFileSeek(File,0,SEEK_END); and everything is written to the file from a new line.
The problem is that there are 4 files and we need to write data on four positions, each in a separate file, each file has a position ticket in the name, but the data are written only to one, the last file, the data on the last position.
Are the file names formed correctly? Instead of Ticket=OrderTicket(); File name=_Ticket+Symbol()+".txt"; would write File name=(string)OrderTicket()+Symbol()+".txt"; and add #property strict directive in the beginning - helps eliminate errors
STARIJ: Are the file names formed correctly? Instead of Ticket=OrderTicket(); File name=_Ticket+Symbol()+".txt"; I would write File name=(string)OrderTicket()+Symbol()+".txt"; and add #property strict directive in the beginning - helps eliminate errors
Thank you, the name formation was redone according to your recommendation, but it still writes only the data of the last position.
And, the names of new files haven't changed) I suspect it's not the name, the file of the last position was found anyway.
1501896125EURUSD.txt Time Half BID Price 2018.02.22 22:53 P 1,23259 0,88322 2018.02.22 22:54 P 1,23259 0,88322 2018.02.22 22:55 P 1,23259 0,88322 2018.02.22 22:56 P 1,23249 0,88322
1501896094EURUSD.txt Time Half BID Price 2018.02.22 22:43 L 1,23212 1,23203 2018.02.22 22:44 L 1,23220 1,23203 2018.02.22 22:44 L 1,23224 1,23203 2018.02.22 22:45 L 1,23244 1,23203 2018.02.22 22:45 L 1,23242 1,23203 2018.02.22 22:46 L 1,23251 1,23203 changed something? see ... this: string sy=""; int op=-1, mn=-1; hardly needed ... can we drop it? In the loop instead of nested if() it's better to continue;
1501896125EURUSD.txt Time Half BID Price 2018.02.22.02.22 22:53 P 1,23259 0,88322 2018.02.22 22:54 P 1,23259 0,88322 2018.02.22 22:55 P 1,23259 0,88322 2018.02.22 22:56 P 1,23249 0,88322
1501896094EURUSD.txt Time Half BID Price 2018.02.22:43 L 1,23212 1,23203 2018.02.22 22:44 L 1,23220 1,23203 2018.02.22 22:44 L 1,23224 1,23203 2018.02.22 22:45 L 1,23244 1,23203 2018.02.02.22 22:45 L 1,23242 1,23203 2018.02.22 22:46 L 1,23251 1,23203 change anything? see...this: string sy=""; int op=-1, mn=-1; hardly needed ... can we drop it? In the loop instead of nested if() it's better to continue;
It doesn't want to write over all the positions.
There are 7 positions open. I have written one file.
I have compiled it when it was on a charts and it has started to write the data of the first and the last positions. Now I have only one data, from the first position.
I can't see six, but I have all ticks inAlert(NameFile).
there are many conditions in the programme, including a condition that must be met in order for the file to be written: if(t_pre+60<TimeCurrent() && _o_t+1800>TimeCurrent()) // once every half an hour from the order opening. Is this necessary? { t_pre=TimeCurrent(); The program contains ramifications:
for(i=0; i<k; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==sy || sy=="")
{
if(OrderType()==OP_BUY ||
OrderType()==OP_SELL)
{
if(op<0 || OrderType()==op)
{
if(mn<0 || OrderMagicNumber()==mn)
{
_o_t=OrderOpenTime();
И еще 5 закрывающих скобок. а можно короче на 10 строк и понятнее записать так
for(i=0; i<k; i++)
{
if( ! OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; // если ошибка выбора ордера - переходим к следующемуif(OrderSymbol()!=sy && sy!="") continue; // а это вообще надо?if(OrderType()!=OP_BUY && OrderType()!=OP_SELL) continue; // а другие разве у Вас есть?if(op>=0 && OrderType()!=op) continue;
if(mn>=0 && OrderMagicNumber()!=mn) continue;
_o_t=OrderOpenTime();
What was the purpose of writing it in a staircase before? In the old version of MQL4 it sped up execution. It is of no importance now The variable _o_t is used only in 2 places. If we replace it with OrderOpenTime(), the program becomes clearer and shorter in 2 lines (declaration and assignment) datetime _o_t; and _o_t=OrderOpenTime();
I've got it - the 60-second countdown has to be taken out of the loop
//+------------------------------------------------------------------+ //| Ежеминутная информация об ордерах, открытых за последнее полчаса | //+------------------------------------------------------------------+ #property strictbool RUS=true;
datetime t_pre=0; // Время предыдущего выполнения//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnTick()
{
if(t_pre+60>=TimeCurrent()) return; // Дождаться 60 секунд после прошлой обработки
t_pre=TimeCurrent(); // Это нужно вынести за цикл - в этом было дело !!!!!!!!!!!!string text;
for(int i=0; i<OrdersTotal(); i++)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
if(OrderType()!=OP_BUY && OrderType()!=OP_SELL) continue;
string ИмяФайла=(string)OrderTicket()+Symbol()+".txt";
Alert(ИмяФайла);
if(OrderOpenTime()+60>=TimeCurrent()) continue; // Пропуск молодых которым меньше 1 минутыif(OrderOpenTime()+1800<=TimeCurrent()) continue; // Пропустк старых которым больше 30 минутif(OrderType()==OP_BUY){if(Bid>OrderOpenPrice())text="P"; else text="L";}
if(OrderType()==OP_SELL){if(Bid<OrderOpenPrice())text="P"; else text="L";}
// Открытие или создание файла и перемещение указателя в конецint Файл= FileOpen(ИмяФайла,FILE_CSV|FILE_READ|FILE_WRITE," ");
if(Файл == -1) { Alert("Ошибка при открытии файла ",ИмяФайла); return; }
FileSeek(Файл,0,SEEK_END);
// Если новый файл записать имя файла и строку заголовков колонокif(FileSize(Файл)==0)
{
FileWrite(Файл,ИмяФайла);
FileWrite(Файл," Время Полу BID Цена ");
}
// Сбор информации и запись в файлFileWrite(Файл, TimeToStr(TimeCurrent()), text,
dstr(Bid), " ", dstr(OrderOpenPrice()));
FileClose(Файл);
}
}
// Преобразование числа double в строку с запятой или точкой в соответствии с локализациейstring dstr(double Цена)
{
if(!RUS) returnDoubleToStr(Цена, Digits);
returnStringSetChar(DoubleToStr(Цена, Digits), StringFind(DoubleToStr(Цена, Digits), "."), ',');
}
Vladislav Andruschenko: I'll tell you more: when trading on a real account with the same broker on 2 different accounts, there can be different results.
It probably depends more on the broker. But could you give me a hint on the initial question?
There isFileSeek(File,0,SEEK_END); and everything is written to the file from a new line.
The problem is that there are 4 files and we need to write data on four positions, each in a separate file, each file has a position ticket in the name, but the data are written only to one, the last file, the data on the last position.
Are the file names formed correctly? Instead of Ticket=OrderTicket(); File name=_Ticket+Symbol()+".txt"; I would write File name=(string)OrderTicket()+Symbol()+".txt"; and add #property strict directive in the beginning - helps eliminate errors
Thank you, the name formation was redone according to your recommendation, but it still writes only the data of the last position.
And, the names of new files haven't changed) I suspect it's not the name, the file of the last position was found anyway.
Why does it ignore the previous positions?
1501896125EURUSD.txt
Time Half BID Price
2018.02.22 22:53 P 1,23259 0,88322
2018.02.22 22:54 P 1,23259 0,88322
2018.02.22 22:55 P 1,23259 0,88322
2018.02.22 22:56 P 1,23249 0,88322
1501896094EURUSD.txt
Time Half BID Price
2018.02.22 22:43 L 1,23212 1,23203
2018.02.22 22:44 L 1,23220 1,23203
2018.02.22 22:44 L 1,23224 1,23203
2018.02.22 22:45 L 1,23244 1,23203
2018.02.22 22:45 L 1,23242 1,23203
2018.02.22 22:46 L 1,23251 1,23203
changed something? see ... this: string sy=""; int op=-1, mn=-1; hardly needed ... can we drop it? In the loop instead of nested if() it's better to continue;
1501896125EURUSD.txt
Time Half BID Price
2018.02.22.02.22 22:53 P 1,23259 0,88322
2018.02.22 22:54 P 1,23259 0,88322
2018.02.22 22:55 P 1,23259 0,88322
2018.02.22 22:56 P 1,23249 0,88322
1501896094EURUSD.txt
Time Half BID Price
2018.02.22:43 L 1,23212 1,23203
2018.02.22 22:44 L 1,23220 1,23203
2018.02.22 22:44 L 1,23224 1,23203
2018.02.22 22:45 L 1,23244 1,23203
2018.02.02.22 22:45 L 1,23242 1,23203
2018.02.22 22:46 L 1,23251 1,23203
change anything? see...this: string sy=""; int op=-1, mn=-1; hardly needed ... can we drop it? In the loop instead of nested if() it's better to continue;
It doesn't want to write over all the positions.
There are 7 positions open. I have written one file.
I have compiled it when it was on a charts and it has started to write the data of the first and the last positions. Now I have only one data, from the first position.
I can't see six, but I have all ticks inAlert(NameFile).
What does it need...
if(t_pre+60<TimeCurrent() && _o_t+1800>TimeCurrent()) // once every half an hour from the order opening. Is this necessary?
{
t_pre=TimeCurrent();
The program contains ramifications:
What was the purpose of writing it in a staircase before? In the old version of MQL4 it sped up execution. It is of no importance now
The variable _o_t is used only in 2 places. If we replace it with OrderOpenTime(), the program becomes clearer and shorter in 2 lines (declaration and assignment)
datetime _o_t; and
_o_t=OrderOpenTime();
I've got it - the 60-second countdown has to be taken out of the loop
Good afternoon, dear forum users.
Can you tell me why the optimization and testing of the same settings sometimes produce different results?
I downloaded quotes from SQ Tick Downloader and ran them through the script
Good afternoon, dear friends.
Can you tell me why the optimization and testing of the same settings sometimes produce different results?
I'll tell you more: when trading on a real account with the same broker on 2 different accounts, there can be different results.
It probably depends more on the broker. But could you give me a hint on the initial question?
It probably depends more on the broker. But could you give some advice on the initial question?