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

 
Sfinks35:
Good afternoon!
I seem to have got it right now:

But when compiling, it gives one warning: possible loss of data due to type conversion on line:
index = GetPatt5barsDN(index);

There are no errors in the function header (or in the function itself) during compilation.

double low3 = 0;
   int index = 0;
   low3 = GetPatt5barsDN(index); // Здесь передача значения по ссылке

   Print("low3= ", low3);
   Print("index= ", index);
 

Greetings, I have a question, is there any way I can skip a certain pass during optimisation.

For example I'm optimizing my robot with 2 MA's - fast and slow starting from 10 and finishing with 1000 for each

How can i skip passes when period of slow one is less than period of fast one?

 
Roman Sharanov:

Greetings, I have a question, is there any way I can skip a certain pass during optimisation.

For example I'm optimizing my robot with 2 MA's - fast and slow starting from 10 and finishing with 1000 for each

How can I skip passes when period of slow one is less than period of fast one?

In this case, do return(INIT_PARAMETERS_INCORRECT) during initialization;

 
Igor Zakharov:

In this case, make return(INIT_PARAMETERS_INCORRECT) during initialisation;

thanks

 

Hello. Who can tell me. Three different TS, three different EAs, with three different magic numbers, on different pairs. But they have a common feature - order closing (using OrderClose() function) when certain conditions are reached(number of orders and small profit). In the tester, there are no problems, but in practice, the impression is that when Order Close() function triggers on one of the pairs, this function (OrderClose()) triggers also on other pairs, whether the conditions are met or not. What may be the reason for this? Maybe it is in the user-defined Close() function?

Below are the closing conditions and the custom Close() function.

if(CountBuy() >= 1 && CountSell() >= 1 && CountSymbolTotal() >= NumberOrder)
   {
      int    i;
      int    total    = OrdersTotal();
      double accruals = CalculateCommission() + CalculateSwapBuy() + CalculateSwapSell();
   
      if((CountProfitBuy() + CountProfitSell()) >= (MaxOrderProfit*GetLots()+ accruals))
      {
         for(i = total-1; i >= 0; i--)
         {
            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            {
               if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
               { 
                  if(OrderType() == OP_BUY)
                     OrderCloseX();
               }
            }
         } 
         for(i = total-1; i >= 0; i--)
         {
            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            {
               if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
               { 
                  if(OrderType() == OP_SELL)
                     OrderCloseX();
               }
            }
         }            
      }
   }
//---------------------
void OrderCloseX()
{
   int i;
   int ticket = -1;
   int k      = OrdersTotal();
   
   for(i = k - 1; i >= 0; i--)
   {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if((OrderType() == OP_BUY || OrderType() == OP_SELL) )
         {            
            ticket = OrderTicket();
         }
      }
   }
   if(OrderTicket() != ticket) 
      if(!OrderSelect(ticket, SELECT_BY_TICKET))
         Print("Ошибка в выборе ордеров!");

   while(true)
   {
      int  error;
      bool result = true;
      
      if (OrderType()==OP_BUY) 
         result = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, 0);
         
      if (OrderType()==OP_SELL) 
         result = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, 0);
         
      if(result != TRUE) 
      { 
         error = GetLastError(); 
            Print("LastError = ", error); 
      }
      else 
      { 
         error = 0; 
      }
      if(error == 135) 
         RefreshRates();
      else break;
   } 
}

 
Youri Lazurenko:

Hello. Who can tell me. Three different TS, three different Expert Advisors, with three different magic numbers, on different pairs. But they have a common feature - order closing (using OrderClose() function) when certain conditions are reached(number of orders and small profit). In the tester, there are no problems, but in practice, the impression is that when Order Close() function triggers on one of the pairs, this function (OrderClose()) triggers also on other pairs, whether the conditions are met or not. What may be the reason for this? Maybe it is in the user-defined Close() function?

Here are the closing conditions and user-defined Close() function.

First, you use OrderSelect() to check orders as it should be - you control the symbol and the order master number, and then you close the order using OrderCloseX() and search through the orders again, but you don't control the symbol and master number in OrderSelect() for some reason

I think we should add OrderCloseX() to avoid rewriting the entire code:

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
 
Igor Makanu:

First you check orders through OrderSelect() as it should be - control the symbol and the order master number, and then you close the order in OrderCloseX() and search through the orders again, but for some reason you do not control the symbol and the master number in OrderSelect()

I think I should add OrderCloseX() in order not to rewrite all code:

Thanks. I will correct it. Already corrected. Maybe this is the reason: the OrderCloseX() function is called on one of the pairs which then works on all other pairs and magic numbers. It may be, it may be. Thanks again.

 
Igor Makanu:

Digits - Predefined Variables

I also decided to use this function, I read that if the number of digits in the office is 5 for example 1.00000 and the last values are zeros it might not return 5 digits but zero or for example the number will look like 1.24700 will return 3 decimal places even though there should be 5 of them is it true?

 
Seric29:

I also decided to use this function, I read that if the number of digits in a stable of 5 characters for example 1.00000 and the last value of zero it may not return 5 characters but zero, or for example the number will look like 1.24700 will return 3 decimal places even though there should be 5 of them is it true?

Digits are used with NormalizeDouble

https://docs.mql4.com/ru/convert/normalizedouble

NormalizeDouble - Преобразование данных - Справочник MQL4
NormalizeDouble - Преобразование данных - Справочник MQL4
  • docs.mql4.com
Рассчитываемые значения StopLoss, TakeProfit, а также значения цены открытия отложенных ордеров, должны быть нормализованы с точностью, значение которой можно получить функцией Digits(). Нужно...
 
All of a sudden, all the terminals have lost connection with the brokers. Everywhere the error connect failed.
In the login window, the server does not allow me to select a server, it's empty. I haven't changed anything before, I haven't installed anything or deleted anything.
What's the reason?
Reason: