Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1520

 
Alexey Viktorov #:

Regarding the magik check, I was talking about something else. You can check for equality and inequality... Some people like to check for inequality and forcibly start a new iteration of the loop. But this approach is simply disgusting to me... I prefer checking for equality. If it is the magician I need, then all commands enclosed in curved brackets after the condition are executed. If the magician is someone else's, then a new iteration of the loop will start without additional stress.

The organisation of the loop can be any. The main thing is that the loop should be complete... This variant works without errors as well as the one in all the documentation examples. You just need to debug the loop organised in the same way as in the documentation examples and watch the loop counter change. Then everything will be clear.

Thank you.

To check for equality, you need to know exactly and list all possible magik numbers. I, of course, cannot know them. Especially, in advance, what robots, with what magicians I will still have.

In any case, both in the variant you suggested and in the variant I took from the article I referred to above, my robots just stopped working. They do not open positions and that's all. Although I can see from the charts that the opening condition is present. I made prints to understand what the values of the variables are equal to. But the prints are not printed to the log file. I found some information about this on the forums sometime ago. People wrote that the documentation stated that prints may not print if there are a large number of them. In other words, not all and not necessarily prints are printed. But for me, almost nothing prints. I still haven't been able to figure it out yet.

It would be nice to have some reliable ways to check for errors.

Right now, I have the following precondition for the robot to start evaluating conditions for opening positions:

   int         total            = PositionsTotal();
   for(int i=total-1; i>=0; i--)
   {
      long   m_position_magic        = k_pos.Magic();
      string m_position_symbol       = k_pos.Symbol();
      ulong  mposition_ticket        = k_pos.SelectByIndex(i);
      Print("total = ",(string)total,", mposition_ticket = ",(string)mposition_ticket,", m_position_magic = ",(string)m_position_magic);
      if(total == 0 || !(mposition_ticket > 0 && m_position_symbol == _Symbol && m_position_magic == Magic_m)) // Нет позиций по инструменту и эксперту

And the second option:

   int         total            = PositionsTotal();
   for(int i=total-1; i>=0; i--)
   {
      string position_symbol       = PositionGetString(POSITION_SYMBOL);
      ulong  position_ticket       = PositionGetTicket(i);
      Print("total = ",(string)total,", position_ticket = ",(string)position_ticket,", magic = ",(string)magic);
      if(total == 0 || !(position_ticket > 0 && position_symbol == _Symbol && magic == Magic_m)) // Нет позиций по инструменту и эксперту

magic and k_pos are global variables. That is why they are not declared in the examples.

I have changed only this part of the code. The precondition used to look like this:

if(!PositionSelect(Symbol())

But the experts worked one by one. The first one who had time to open a position was the first to work.

 
maxvoronin74 #:

Thank you.

To check for equality, one would have to know exactly and list all possible magik numbers. Of course, I can't know them. Especially, in advance, which robots with which magicians I will still have.

Are you sure you're not confusing a magik with a ticket???

You set the magick you want. Each Expert Advisor has its own magik and all orders and positions are identified by this magik. Therefore, if you set Magic = 123 in an Expert Advisor, then all positions opened by this Expert Advisor will have Magic 123.

Hence, by searching all positions, you START by getting a position ticket, thus selecting a position to work with its properties

      ulong  position_ticket       = PositionGetTicket(i);

And only then you start checking the magic. If there is such a position among the open positions, you return the prohibition to open a position - false. If there is no such magik among all positions, the check function should return the permission to open a position - true.

Even if we take your variant

   int         total            = PositionsTotal();
   for(int i=total-1; i>=0; i--)
   {
      long   m_position_magic        = k_pos.Magic();
      string m_position_symbol       = k_pos.Symbol();
      ulong  mposition_ticket        = k_pos.SelectByIndex(i);
      Print("total = ",(string)total,", mposition_ticket = ",(string)mposition_ticket,", m_position_magic = ",(string)m_position_magic);
      if(total == 0 || !(mposition_ticket > 0 && m_position_symbol == _Symbol && m_position_magic == Magic_m)) // Нет позиций по инструменту и эксперту

you have a broken sequence of actions.

Receiving a position ticket and selecting it to work with should be the first line in the loop.

And then, it would be nice to see where this loop is organised. In the main code or in a separate user function.

 
Good afternoon!
Could you please tell me how to write a matrix to a csv file ?
 
Alexey Viktorov #:

Are you sure you're not confusing a magik with a ticket?

You set the magick you want. Each Expert Advisor has its own Magic and all orders and positions are identified by this Magic. Therefore, if you set Magic = 123 in an Expert Advisor, then all positions opened by this Expert Advisor will have Magic 123.

Therefore, by searching all positions, you START by getting the position ticket, thereby selecting the position to work with its properties

And only then you start checking the magic. If there is such a position among the open positions, you return the prohibition to open a position - false. If there is no such magik among all positions, the check function should return the permission to open a position - true.

Even if we take your variant

you have a broken sequence of actions.

Receiving a position ticket and selecting it to work with should be the first line in the loop.

And then it would be nice to see where this loop is organised. In the main code or in a separate user function.

I don't confuse magick with ticket.

I had variants with trailingstop and locks. There I made separate functions. And here the rules are simpler, everything is in OnTick.

Thank you. I have moved the line of receiving a ticket to the head of the loop. I can see from the charts that the condition for opening a position is present, but the positions are not opened....

If you can advise on how to effectively check for errors, it would be much appreciated. Prints are printed after one or not printed at all.

 
maxvoronin74 #:
Prints are printing one after another or not printing at all

As my first electronics tutor used to say (yes, yes, electronics - I'm not confusing anything!), he used to say: there are NO miracles in the world!!!! )) What's the point of this speech? It means that at some moments you simply do not get to the printing of prints. Look for problems in your code. And, yes! Try to master the debugger in the meta-editor. It's a great tool to get rid of miracles. ))

Regards, Vladimir.

 
Perhaps they are just not visible in the terminal tab. Open the log file and you will see the prints.
 
MrBrooklin #:

As my first electronics tutor used to say (yes, yes, electronics - I'm not confusing anything!), he said: there are NO miracles in the world!!! )) What's the point of this speech? It means that at some moments you simply do not get to the printing of prints. Look for problems in your code. And, yes! Try to master the debugger in the meta-editor. It's a great tool to get rid of miracles. ))

Regards, Vladimir.

About the fact that the documentation states that not everything can be printed, I read in another thread of this forum. I did not bookmark it. I am unlikely to find it. Written by an experienced person. So I am not deceiving you.

I used to have several functions in the robot's code. And to understand which function the programme is now in, I placed a print with the text "You have entered such and such function" in the head of the function. Inside there were prints with the names and values of variables at different stages and comments. Sometimes I open a log file and see a whole column with "Entered such and such function". And then suddenly the column below changes to lines with variable names and values. And "entered the function" is not necessary to print anymore. Or there are errors on which the prints are written. There are errors. There are no error prints. It's like this all the time. So the selective operation of printers definitely takes place. It's just that the algorithm is not clear. Now, it seems, the code is simpler, but printers almost do not work.

If you can advise me where to read about the debugger's work, I will be grateful.

Well, and off topic. Those who have not seen them say that miracles do not happen.

 
Roman Kutemov Open the log file and you will see the prints.

I don't know how to open the terminal tab where you can see the prints. And did not bother with the information. I look in the log file itself, in the MQL5 folder.

 
maxvoronin74 #:

Just how to open the terminal tab where the prints are visible, I don't know. I didn't bother with the information. I look in the log file itself, in the MQL5 folder.

The picture shows the tab where you should look at the prints.

Regards, Vladimir.


 
MrBrooklin #:

The picture showed the tab where you need to look at the printout of the prints.

Regards, Vladimir.


Thank you. I've seen it. Does it show only today's prints or can I set it to show prints for other days?
Reason: