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

 
for(int h = OrdersTotal()-1; h >= 0; h--) // Начинаем цикл перебора ордеров
    {
     if(OrderSelect(h, SELECT_BY_POS)) //Выбираем ордер с индексом h
      {
       if((cnt_OO >= 2))//Если cnt_OO больше либоравно 2 выполняем блок иначе переходим к Метке 1
        {
       if((OrderMagicNumber() == Magic)&&(OrderLots() <= Lots/Prikup - Dplus))//Если мейджик выбраного ордера совпадает и лотность совпадает с Lots/Prikup - Dplus
//(если переменные типа double необходимо обязательно нормализовать) выполняем блок иначе переходим к Метке 1
        {
         Nextstep  = NextStep;
         BaseNext  = OrderOpenPrice();
         LotsNext  = NormalizeDouble(OrderLots()*K,lotDigit);
         if(NewPB > 0)
          PBcloseON = true;
         Alert ("Pospedny Order NEXT  ",OrderTicket());
         Alert ("Otkritih orderov  ",cnt_OO);
        break; //Прерываем цикл
        }}
//Метка 1
         LotsNext    = NormalizeDouble(Lots*Prikup,lotDigit); 
         Alert ("Otkritih orderov NEXT net ");
        Alert ("Otkritih orderov  ",cnt_OO);
         break;// Прерываем цикл 
     
        }}

The first problemLots/Prikup - Dplus must be normalized. Read about it carefully. If the variables are of double type, you'll be surprised if 4/2 gives out not the expected 2, but 1.999999999999 - you probably have not faced with this problem yet.

So if((OrderMagicNumber() == Magic)&&(OrderLots() <= Lots/Prikup - Dplus)) is false, and I can say with high probability that it is false, then even if you have cnt_OO greater than 1 you are guaranteed to come to a block after label 1. So everything works with you without errors The problem is in data processing logic.

The second problem is that you are guaranteed to process only the last order in the list, so why bother with a for loop?

If you do this only for the tester, then choosing the last order from the list, you really will get the needed order, and not always. On the real market, especially if there are several Expert Advisors running, you are guaranteed to get something different than you expect and the loop is guaranteed to break after the first pass using the break command.

 
Vitaly Gorbunov:

The first problemLots/Prikup - Dplus must be normalized. Read about it carefully. If the variables are of double type, you'll be surprised if 4/2 gives out not the expected 2, but 1.999999999999 - you probably have not faced with this problem yet.

So if((OrderMagicNumber() == Magic)&&(OrderLots() <= Lots/Prikup - Dplus)) is false, and I can say with high probability that it is false, then even if you have cnt_OO greater than 1 you are guaranteed to come to a block after label 1. So everything works with you without errors The problem is in data processing logic.

The second problem is that you are guaranteed to process only the last order in the list, so why bother with a for loop?

If you do this only for the tester, then choosing the last order from the list, you really will get the needed order, and not always. On the real market, especially if there are several Expert Advisors running, you are guaranteed to get something different from what you expect and the loop will break after the first pass.

Vitaly Gorbunov:

The first problemLots/Prikup - Dplus must be normalized. If the variables are of double type you will be surprised if 4/2 gives out not the expected 2 but 1.999999999999 perhaps you haven't faced this problem yet

So if((OrderMagicNumber() == Magic)&&(OrderLots() <= Lots/Prikup - Dplus)) is false, and I can say with high probability that it is false, then even if you have cnt_OO greater than 1 you are guaranteed to come to a block after label 1. So everything works with you without errors The problem is in data processing logic.

The second problem is that you are guaranteed to process only the last order in the list, so why bother with a for loop?

If you do this only for the tester, then choosing the last order from the list, you really will get the needed order, and not always. On the real market, especially if there are several Expert Advisors running, you are guaranteed to get exactly the wrong order, and the loop will break on the break command after the first pass.

As for normalization - thanks, I hadn't noticed it was missing. My eye just got lost in my head.

About the for loop: there are different orders in the archive with different mages and from different pairs. I go through them from the end until I find the one I need. This happens when the EA has not started working and no new orders I need appear in the list. The loop is interrupted not at the first pass, but when the required order is found.

We have to understand the functions Onlinit and OnDeinit properly. Their necessity is obvious.

 

In this implementation, the loop does not work. I ran your code in different variants always one pass.

And now I see where you got it wrong!

for(int h = OrdersTotal()-1; h >= 0; h--) // Начинаем цикл перебора ордеров
    {
     if(OrderSelect(h, SELECT_BY_POS)) //Выбираем ордер с индексом h
      {
       if((cnt_OO >= 2))//Если cnt_OO больше либоравно 2 выполняем блок иначе переходим к Метке 1
        {
       if((OrderMagicNumber() == Magic)&&(OrderLots() <= Lots/Prikup - Dplus))//Если мейджик выбраного ордера совпадает и лотность совпадает с Lots/Prikup - Dplus
//(если переменные типа double необходимо обязательно нормализовать) выполняем блок иначе переходим к команде continue
        {
         Nextstep  = NextStep;
         BaseNext  = OrderOpenPrice();
         LotsNext  = NormalizeDouble(OrderLots()*K,lotDigit);
         if(NewPB > 0)
          PBcloseON = true;
         Alert ("Pospedny Order NEXT  ",OrderTicket());
         Alert ("Otkritih orderov  ",cnt_OO);
        break; //Прерываем цикл
        }

        continue; //Вернёмся в цикл за следующим ордером если предыдущий не прошёл проверку
       }
//Метка 1
         LotsNext    = NormalizeDouble(Lots*Prikup,lotDigit); 
         Alert ("Otkritih orderov NEXT net ");
        Alert ("Otkritih orderov  ",cnt_OO);
         break;// Прерываем цикл 
     
        }}

I commented everything as much as possible! Try it!

 
Vitaly Gorbunov:

In this implementation, the loop does not work. I ran your code in different variants always one pass.

And now I see where you got it wrong!

I commented everything as much as possible! Try it!

Thanks, I got it. Here is a workaround for the error of lack of normalization. After closer examination of the recovery algorithm, Condition&&(OrderLots() <= Lots/Prikup - Dplus) appeared to be unnecessary.

Thank you all for your good advices



Here is the result of testing. It's about the same on the real, even better. Be warned in advance - this is not a martingale. It's even worse than you think :=). Drawdown 1.3% profit 507$

 
Good result! Any more problems, but it's hard to get the information you need to pinpoint the problem. If you want, you can add me as a friend so that I don't get lost.
 
Vitaly Muzichenko:

If it works, and you don't mind sharing the result - write a solution to the problem

It didn't work (I used the php openssl library). Solved the problem in a different way.

 
Juer:

Didn't work (I used the php openssl library). Solved the problem in a different way.

So you ended up encrypting in MT and decrypting in .php ? Which way did you use?

 
Vitaly Muzichenko:

So you ended up encrypting in MT and decrypting in .php ? What method did you use?

No, I told you, it didn't work. I gave up on it. For my task a hash was enough. I was sending and receiving hash and back another hash as a confirmation.

So I was unable to decrypt it in PHP. It would be nice if someone could seriously look into this issue. Maybe a developer or something.

 
Juer:

No, I wrote that it didn't work. I gave up on it. A hash was enough for my task. I sent and received a hash and back another hash as confirmation.

So I was unable to decrypt it in PHP. It would be nice if someone could seriously look into this issue. Maybe a developer or something.

Write your own encryption function in puch, and move it to mq. That way they won't decrypt it, and it will work 100% either way.

 
Vitaly Muzichenko:

If it works, and you don't mind sharing the result, post the solution

google "PKCS#7 padding format"

Reason: