Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1145

 
Artyom Trishkin:

I've already answered you:

You take the last order on the list:

And you first need to find out how much the status of the order list has changed. It was 12, became 8 - it has changed by 4 orders. Accordingly - you need to print all four orders. And you always print only the last one in the list.

How do you know how much it has changed? When you start the EA, you should write the number of orders in a variable, for example, int last_total. Then, on each tick, compare the OrdersTotal() with last_total. If they are NOT equal, that is a change. Write the difference between OrdersTotal() and last_total into a variable, for example, num_changes and save the new state of OrdersTotal() to last_total.
There may be some subtleties here, for example, when a pending order is triggered. But for now, you should do what you need to do first.
Knowing the number of pending orders, you can look them up in the history. However, you can also limit the monitoring of orders in the history list - do all of the above for the list of historical orders, and not for the list of market orders. The difference between what was and what has become - this is the amount of orders you need to analyze. You always analyze only the last order in the list.

However, this cannot guarantee that the last order in the history list will be the last closed order. This is also a nuance that must be considered. But then.

Thank you very much. That makes it much clearer. Key words - you should print not just one but 4 orders at a time. If you'd told me in the first post I wouldn't have tortured you.

 
ANDREY:

Thank you very much. That makes a lot more sense. The key words are to print not one but 4 orders at a time. If you'd told me in the first post I wouldn't have tortured you.

You're welcome. Until you learn for yourself to make logic of this or that action, you will not move from the dead point - you will ask on the forum. You will be asking questions on the forum. It does not have to be linked to orders/lists/tickets etc...

I think that if you were using apples, you could easily create an algorithm to keep track of how many apples are on the table, then you go out for a smoke and come back - there are fewer apples...
How do you know that? Easy - 5 apples, 3 apples. Two are missing. The cat must have... Or there were five and now there are six. One came out. From the damp, maybe... In either case, you counted the difference in your mind.

So how is the same action different from counting orders? Same apples... Instead of "in mind" write "in function"

 

please advise how to remove the function from the code(decomposition), if there are already more than 200 lines of code and it's inconvenient to browse it all. I am interested in "mechanics": how the function is "decomposed", where it is written, in order to call it later in the main code.

If you have an example with a description, I'd appreciate a link
 
Alexey Kolybelnikov:

please advise how to remove the function from the code(decomposition), if there are already more than 200 lines of code and it's inconvenient to browse it all. I am interested in "mechanics": how the function is "decomposed", where it is written, in order to call it later in the main code.

If there's an example with a description, I'd appreciate a link

Used to be:

double a = (b + c) / (d - e);


Became:

double a = Add(b,c) / Sub(d,e);

//---------

Add(const double v1,const double v2) { return v1 + v2; }

Sub(const double v1,const double v2) { return v1 - v2; }
 
Artyom Trishkin:

You're welcome. Until you learn how to formulate the logic of this or that action for yourself, you will not move from the dead point - you will be asking questions on the forum. And the logic cannot get any easier - it can be put together in simple words. It does not have to be tied to warrants/lists/tickets etc...

I think that with apples you can easily create an algorithm for tracking their quantity - everything is like in real life: you remember how many apples are on the table, you go out for a smoke, and when you come back there are less apples...
How do you know that? Easy - 5 apples, 3 apples. Two are missing. The cat must have... Or there were five and now there are six. One came out. From the damp, maybe... In either case, you counted the difference in your mind.

So how is the same action different from counting orders? Same apples... Instead of "in the mind" write "in the function"

Understood. Thanks for the clarification. The same question has been on my mind for a long time.... My code assumes thatthe Print() function will be printed in the journal frequently. Automatically in the journal will be printed each open order and each close of each order. I have a lot of orders. Correspondingly, there would be a lot of records about the orders. These records often stop me from getting data from the Print() function, which can also be very numerous.

Q: .

How can I make it so that, when I need it, the information about open and closed orders is not shown in the journal, but only in the Print() function is shown.

Can it be done with the help of some MQL4 function or should I change the code of the MT4 terminal?

Thank you.
 
ANDREY:

Got it. Thanks for the clarification. The same question has been on my mind for a long time.... My code assumes that the Print() function will be printed in the journal frequently. Automatically in the log will be printed each open order and each close of each order. I have a lot of orders. Correspondingly, there would be a lot of records about the orders. These records often stop me from getting data from the Print() function, which can also be very numerous.

Q: .

How can I make it so that, when I need it, the information about open and closed orders is not shown in the journal, but only in the Print() function is shown.

Can it be done using some MQL4 function, or it requires changes in the MT4 terminal code?

Thank you.

If you do the research, you better write it in a file. I do not know how to display actions with orders in the log file and I think there is no such a thing. This is the level of entries of the beginning and the end of the EA operation. These are log file entries. The file will contain only what you want, the log will contain terminal records in addition to yours. You can make changes in the terminal, you can even write your own))) but how much will it cost?

 
Alexey Kolybelnikov:

please advise how to remove the function from the code(decomposition), if there are already more than 200 lines of code and it's inconvenient to browse it all. I am interested in "mechanics": how the function is "decomposed", where it is written, in order to call it later in the main code.

If there is an example with a description, I would be grateful for a link

https://www.mql5.com/ru/docs/runtime/imports

https://www.mql5.com/ru/docs/basis/preprosessor/include

and further on the links... In general: put everything "extra" in the *.mqh library, at the beginning of the main code. The compiler will "glue" it together

But in general, 200 lines is not too much - using buttons you can feel comfortable with more than a thousand lines.

 
Valeriy Yastremskiy:

If you are doing research it is better to write to a file. I don't know how to display order actions in the log file and I don't think there are any, this is the level of the start and end records of the EA. These are log file entries. The file will contain only what you want, in addition to your entries, the log will contain terminal entries. You can make changes in the terminal, you can even write your own))) but how much will it cost?

Thanks for the tip. But I don't think I have ever written an EA in a file. I have always written EAs in MetaEditor 4. To see what Pront() output for the whole testing period, I choose Log - Open tab. A file opens in Notepad with the same content as in the Log tab. It seems to me it is a log file.
But it seems to me I am unable to delete all open and closed orders from this file in Notepad. To be more precise, you do. But it is very tedious and time-consuming work.
I would be very grateful to you if you tell me the secret how to make my code opened and closed orders, but in the file, the information on the opening and closing of all orders were not, but only a record of the Pront() function.
Thanks for the help.

 
ANDREY:


Do you know where I can read more about the latest updates of MQL4? There is a lot of information, but it's hard to find what you need.

https://www.mql5.com/ru/forum/160683/page1109#comment_15711102

Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
Любые вопросы новичков по MQL4 и MQL5, помощь и обсуждение по алгоритмам и кодам
  • 2020.03.31
  • www.mql5.com
В этой ветке я хочу начать свою помощь тем, кто действительно хочет разобраться и научиться программированию на новом MQL4 и желает легко перейти н...
 
ANDREY:

Thanks for the tip. But I don't think I ever wrote EA in a file. I have always written EA in MetaEditor 4. To see what the Pront() function output for the whole test period, I select Log - Open tab. A file opens in Notepad with the same content as in the Log tab. It looks like a log file to me.
But it seems to me I am unable to delete all open and closed orders from this file in Notepad. To be more precise, you do. But it is very tedious and time-consuming work.
I would be very grateful to you if you tell me the secret of how to make my code opened and closed orders, but in the file, information about opening and closing all orders were not, and there were only entries of the Pront() function.
Thanks for the help.

int OnInit()
  {   
//----------
   FileTest() // функция открытия файла записи данных
   point = 1/Point; // чтобы не делить на пойнт
   tx=TimeCurrent();// задание времени начала работы советника
//--- create timer
   EventSetTimer(60);

//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {

   FileClose( Handle );                // Закрываем файл
   Alert("Файл ",File_Name," закрыт.");// Сообщение
     
//--- destroy timer
   EventKillTimer();

  }

void OnTick()    // Функция start() раньше называлась
  {
.................
 Qnt_Symb=FileWrite(Handle,Symbol()," ТФ ",Period(),"Открыт ордер Buy по цене ",Ask,
            "Ticket = ",Ticket," ProfB=",ProfB," MxProfB=",MxProfB, " ProfS=",ProfS," MxProfS=",MxProfS);//Запись в файл
            if(Qnt_Symb<=0) // Если не получилось
              {
               Alert("Ошибка записи в файл ",GetLastError());// Сообщение
              };
.................
}
//-------------------------------------------------------------- 12 --

int FileTest()
  {
   Handle=FileOpen(File_Name,FILE_CSV|FILE_WRITE,";");//Открытие файла
   if(Handle==-1) // Неудача при открытии файла
     {
      Alert("Ошибка при открытии файла. ",// Сообщение об ошибке
            "Возможно, файл занят другим приложением");

     }

   return(Handle);
  }
//+------------------------------------------------------------------+

In the tester, the file will be in the folder \tester\files, and if you put it on the window, it will be in the folder \MQL4\Files. And Kovalev has it in detail.

Reason: