Troubled by the error there are no trading operations - page 14

 
Maxim Kuznetsov:

think about what will happen at Stop Out. (you already have Margin Call, Steppe is closer than ever)

your trade will be forcibly closed, but you ignore such an option, and you will be looking for it every tick (in history, it's long) and sending incorrect orders.

Just to add for anyone who has "more than 10 years of MQL programming"

If something can happen, it will definitely happen.

Stop Out and Margin Call are not that normal, but it's natural, and an EA should be ready for them.

Trading conditions may change, they are not constant. StopLevel jumps and even leverage changes sometimes.

The user can easily set/change Stop/Take or close a position, even unintentionally - the Expert Advisor should react to this

A user can open/close an order with Magic (or accidentally set Magic=0 and trade by hand) - what will the robot do?

Balance is deposited/withdrawn without restarting the EA - it is extremely important that the robot is able to do this (there was a topic recently - a man just lost money)

The terminal may reboot and take a long time to update, or the connection may be lost for a significant time - all of this and everything that happened offline should be taken into account

Validator only checks 1-2% of the "candidate minimum" and people still complain...

 
Renat Akhtyamov:

seems to have been written sequentially, question - answer

all pages of the thread are accessible.

Renat, I understand that you are counting warrants. I don't understand why?


Maxim Kuznetsov:

Just to add for all those who have "more than 10 years of MQL programming".

If something can happen, it will definitely happen.

Stop Out and Margin Call are not that normal, but it's natural, and an EA has to be ready for them

Trading conditions may change, they are not constant. StopLevel jumps and even leverage changes sometimes.

The user can easily set/change Stop/Take or close a position, even unintentionally - the Expert Advisor should react to this

A user can open/close an order with Magic (or accidentally set Magic=0 and trade by hand) - what will the robot do?

Balance is deposited/withdrawn without restarting the EA - it is extremely important that the robot is able to do this (there was a topic recently - a man just lost money)

The terminal may reboot and take a long time to update, or the connection may be lost for a significant time - all of this and everything that happened offline should be taken into account

Validator is checked by only 1-2% of "candidate minimum" and people still complain...

Maxim, what are you talking about?! What have I asked for advice on what to do when I get a stop out. Read the forum from page 6, in my opinion I have set out my question in great detail.

 
Andrey Kaunov:

Renat, I understand that you are counting warrants. I don't understand why?


Maxim, what are you talking about?! Did I ask for advice on what to do with a stop out? Read the forum on page 6, I think I have set out my question in great detail.

because the tickets on the real are not 0,,,,N

 
Oh, you mean my little code. So it doesn't matter what kind of tickets there are. Renat there is a two-dimensional array. In cell [0] it writes a ticket, and in cell [1] it counts orders. We could do it with different variables, but I decided to do it that way.
 
Andrey Kaunov:

Renat, I understand that you are counting warrants. I don't understand why?


Maxim, what are you talking about?! Did I ask for advice on what to do with a stop out? Read the forum from page 6, in my opinion I have stated my question in great detail.

with your 10 years of experience, what can i advise...nothing in principle :-)

You're ignoring my advice and demanding a validator for your EA.

---

you got a stop out on NZDUSD, an order was closed, your EA's logic doesn't matter, you still select it and send OrderClose, you get false. This amazing operation is repeated on every tick, the whole thing slows down and the check is canceled. And this is in the simplest case.

About trade condition checks - see previous 14 pages

 
Andrey Kaunov:

Pay attention to this post of yours:

Forum on trading, automated trading systems and trading strategy testing

Tired of the error there are no trading operations

Andrey Kaunov, 2020.07.25 11:42

I will try it, Renat, thank you for the tip.

Vladimir, can you understand the question constructively? Don't I check the lot for margin and so on?The article "What checks must pass..." is already like a bible to me. I've posted code snippets above. I've changed the code according to your recommendations from the article for full compliance:

//+------------------------------------------------------------------+
//| Функция нормализации лота                                        |
//+------------------------------------------------------------------+
double NormalizeLots(string symbol, double lot, int direction, bool is_margin=true) {
   if(lot<=0) return(0.0);
   RefreshRates();
   double min=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
   double max=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
   double step=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP); 
   //double free = AccountFreeMargin()*0.95;
   //double margin = MarketInfo(symbol,MODE_MARGINREQUIRED);
   double _lot=lot<min?min:(lot>max?max:lot);
          _lot=MathRound(_lot/step)*step;
   //if(is_margin && _lot*margin>free)  _lot=0.0;
   ResetLastError();
   if(is_margin && (AccountFreeMarginCheck(Symbol(),direction,_lot)<=0 || GetLastError()==134)) _lot=0.0;
   return(_lot);
}

But I still get "no trades":

Well, if function always sends 0.0 lot and does not allow to open trades, I change it to send minimum lot:

//+------------------------------------------------------------------+
//| Функция нормализации лота                                        |
//+------------------------------------------------------------------+
double NormalizeLots(string symbol, double lot, int direction, bool is_margin=true) {
   if(lot<=0) return(0.0);
   RefreshRates();
   double min=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MIN);
   double max=SymbolInfoDouble(symbol,SYMBOL_VOLUME_MAX);
   double step=SymbolInfoDouble(symbol,SYMBOL_VOLUME_STEP); 
   //double free = AccountFreeMargin()*0.95;
   //double margin = MarketInfo(symbol,MODE_MARGINREQUIRED);
   double _lot=lot<min?min:(lot>max?max:lot);
          _lot=MathRound(_lot/step)*step;
   //if(is_margin && _lot*margin>free)  _lot=0.0;
   ResetLastError();
   if(is_margin && (AccountFreeMarginCheck(Symbol(),direction,_lot)<=0 || GetLastError()==134)) _lot=min;
   return(_lot);
}

And I get the history that trades do occur (see screenshots below). But the minimum lot of course comes very strange, but let it comes. But the deals are there!

That is in this situation, very strange thing is validator, making a minimum lot 0.2 for a deposit of $ 1.


Naturally, there will be no deals at all! And this is with a perfectly adequate code. By the way, I have removed all conditions on indicators, etc. for testing. The trades begin to be opened as soon as the Expert Advisor is launched.

So what does the validator do? I think so far the only thing it does is blow the programmers' minds!

Note that I'm not asking to change anything in the validator. We can simply see the testing logs. We will understand then with what parameters the tests are running and on what deposits. At the end of the day, we may at least use prints to check where the error is in the code and fix it as fast as possible. We will not be pointing our fingers in the sky for a whole week, trying only to localize an error. We are not working against each other, are we? I understand, we are trying to earn something together.

Your very first screenshot. You've attached yourself to the message that there are no trades on NZDUSD. And you've been fighting this mill for 14 pages.

But the main error in the first screenshot is not that one. It's the one informing you about too long testing on GBPUSD. Because the test lasted too long, the validator timeouted it.

Run the code profiler on GBPUSD, M30 and let it trade for three hours. Then look at the bottlenecks and fix them.

 
Maxim Kuznetsov:


---

You have a stop out on NZDUSD, you have closed an order, your Expert Advisor's logic does not care, you still select it and send OrderClose, you get false. This amazing operation is repeated on every tick, the whole thing slows down and the check is canceled. And this is in the simplest case.

About checking trade conditions - see previous 14 pages.

Maxim, you are reading the code very inattentively.

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
   gl_lots=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   gl_ask=NormalizeDouble(Ask,_Digits);
   gl_bid=NormalizeDouble(Bid,_Digits);
   gl_comm="test";
//---
   if(AccountFreeMarginCheck(_Symbol,OP_BUY,gl_lots)<=0 || GetLastError()==134) {
      printf("Not enough money for the minimum lot: %.4f",gl_lots); 
      return;
   }
   if(test_ticket[1]<8 && test_ticket[0]==0) {
      test_ticket[0]=OrderSend((StringCompare(_Symbol,"NZDUSD")==0?"NZDUSD":_Symbol),OP_BUY,gl_lots,gl_ask,30,0.0,0.0,gl_comm,33333,0,clrNONE);
      if(test_ticket[0]>0) test_ticket[1]++;
      else if(Fun_Error(GetLastError())==1) return; 
   }   
   if(test_ticket[0]>0)
      if(OrderSelect(test_ticket[0],SELECT_BY_TICKET)) {
         if(OrderCloseTime()==0 && OrderOpenTime()+300<TimeCurrent())
            if(OrderClose(test_ticket[0],OrderLots(),gl_bid,30,clrNONE)) {
               printf("Test order closed, ticket #%d",test_ticket[0]);
               test_ticket[0]=0;
            } else if(Fun_Error(GetLastError())==1) return;
      } else if(Fun_Error(GetLastError())==1) return;
}

The condition mentioned in the marker won't let the OrderClose() function run away if the order is closed, this is the first thing. And second, if at least one order is open on NZDUSD, the validator wouldn't return "no trade".

Artyom Trishkin:

...

Run the code profiler on GBPUSD, M30 and let it trade for three hours. Then look at the bottlenecks and fix them.

Ok, Artyom. I'll give it a try.

 
Andrey Kaunov:

Maxim, you have read the code very inattentively.

The condition specified by the marker will not let the OrderClose() function escape, this is the first thing. And second, if at least one order was opened on NZDUSD, the validator wouldn't return "no trade".


Frankly speaking, I'm tired of acting as a debugger of a crooked code and trying to fight the author's self-confidence. The specified errors are there, look for yourself

If you do not know what to do with it, you will have to do something for your own profit. Validator has nothing to do with it

 
I'm not asking you personally, Maxim, to debug anything. The code is crooked, fine, but it passes validation. The question is quite different.
 
Artyom Trishkin:

...

Run code profiler on GBPUSD, M30 and let it trade for three hours. Then look at the bottlenecks and fix them.

Artyom, the code profiler has not shown any bottlenecks. The entire code runs smoothly, without any pathologically long processes.

The bottom line of this whole story is this. By hook or by crook, I finally passed the validation. It doesn't depend on the code at all (if it's correct, without any obvious errors, as mentioned in this article). How the validator works is obviously known only to its creator. The code is checked after 2 times and then on the third time. Sometimes it passes several times in a row and sometimes it doesn't at all. What's more, I only change input parameters (they're not significant) or shift the lines which don't change anything when rearranging them, or even remove or add comments (which shouldn't affect the working file in any way).

In general, pass or fail validation, depends only on the "mood" validator (voltage in the network, some kind of power flow or whatever). Thus the code in the usual tester at normal parameters never hung and did not give any failures, on any pairs and TF.

Reason: