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

 
Tretyakov Rostyslav #:
Where does your flag reset?
//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену и текста
   if(CountTrade() == 0)
     {
      flag_close=0;
      ObjectsDeleteAll(0,"AveragePriceLine");
      if(ObjectFind(0,"signal4")==0 && CountTrade(0) < 1)//для бай
        {
         ObjectDelete(0,"signal4");
        }
      if(ObjectFind(0,"signal3")==0 && CountTrade(1) < 1)//для селл
        {
         ObjectDelete(0,"signal3");
        }
     }

If I put it in here it would be right

 
EVGENII SHELIPOV #:

If I put it in here, it'll be right.

No. This way it will reset when all orders are closed.

Considering that you do not need to close all the orders, it is better to re-run the tickets and close them.

 
Tretyakov Rostyslav #:

No. This way it will reset when all orders are closed.

Considering that you don't need to close all orders, it's better to re-run the tickets and close

Just a minute.

 
EVGENII SHELIPOV #:

Just a moment.



//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену мин и макс ордеров и текста
   if(CountTrade() == 0 || Drawdown < DrawdownClosingMinMaxOrdersZero)
     {
      flag_close2=0;
      flag_close3=0;
      ObjectsDeleteAll(0,"AveragePriceLineMinMaxOrders");
      if(ObjectFind(0,"signal41")==0 && (CountTrade(0)<1 || Drawdown < DrawdownClosingMinMaxOrdersZero)) //для бай
        {
         ObjectDelete(0,"signal41");
        }
      if(ObjectFind(0,"signal42")==0 && (CountTrade(1)<1 || Drawdown < DrawdownClosingMinMaxOrdersZero))//для селл
        {
         ObjectDelete(0,"signal42");
        }
     }

but this way.

 
Tretyakov Rostyslav #:

No. This way it will reset when all orders are closed.

Taking into account that you do not need to close all orders, it is better to loop through the tickets and close them.

Don't I go through the tickers in the close order function?

//+----------------------------------------------------------------------------+
//| Закрытие минимального максимального и предпоследнего ордеров               |
//+----------------------------------------------------------------------------+
void  ClosseMinMaxPenultimateOrders()
  {
   int slipp = (int) MarketInfo(_Symbol,MODE_SPREAD)*2;
   for(int i = OrdersTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            if(OrderType() == OP_BUY)
              {
               if(CalculiteProfitMinMaxPenultimateOrders() >= 0 && OrderGroupCloseSignal()==0 &&
                  Drawdown >= DrawdownClosingMinMaxOrders && FindPenultimateProfit() > 0)
                 {
                  if(OrderClose(GetTicketPenultimateOrder(), FindPenultimateLots(), Bid, slipp) && OrderClose(GetTicketMinOrder(), GetMinLotOrder(), Bid, slipp) &&
                     OrderClose(GetTicketMaxOrder(), FindLastLots(), Bid, slipp))
                    {
                     SendNotification("Закрылся минимальный максимальный и предпоследний ордера на покупку: " + Symbol() + ", Баланс: " + DoubleToString(NormalizeDouble(AccountBalance(), 2))
                                      + ", Свободно денежных средств: " + DoubleToString(NormalizeDouble(AccountFreeMargin(), 2)));
                     Print("Максимальный и минимальный ордера на покупку успешно закрыты!");
                    }
                  else
                    {
                     Print("Не удалось закрыть максимальный и минимальный ордера на покупку!",GetLastError());
                    }
                 }
              }

            if(OrderType() == OP_SELL)
              {
               if(CalculiteProfitMinMaxPenultimateOrders() >= 0 && OrderGroupCloseSignal()==1 &&
                  Drawdown >= DrawdownClosingMinMaxOrders && FindPenultimateProfit() > 0)
                 {
                  if(OrderClose(GetTicketPenultimateOrder(), FindPenultimateLots(), Ask, slipp) && OrderClose(GetTicketMinOrder(), GetMinLotOrder(), Ask, slipp) &&
                     OrderClose(GetTicketMaxOrder(), FindLastLots(), Ask, slipp))
                    {
                     SendNotification("Закрылся минимальный максимальный и предпоследний ордера на продажу: " + Symbol() + ", Баланс" + DoubleToString(NormalizeDouble(AccountBalance(), 2))
                                      + ", Свободно денежных средств" + DoubleToString(NormalizeDouble(AccountFreeMargin(), 2)));
                     Print("Максимальный и минимальный ордера на продажу успешно закрыты!");
                    }
                  else
                    {
                     Print("Не удалось закрыть максимальный и минимальный ордера на продажу!",GetLastError());
                    }
                 }
              }
           }
        }
     }
  }
 
EVGENII SHELIPOV #:


but like this.

//-------------------------------------------------------------------+  Команда на удаление линий отображающую среднюю цену мин и макс ордеров и текста
   if(CountTrade() == 0 || Drawdown < DrawdownClosingMinMaxOrdersZero)
     {
      flag_close2=0;
      flag_close3=0;

It means if there are no orders

 
Tretyakov Rostyslav #:

It means if there are no orders

Yes, or if the drawdown is below a certain level. But as far as I understand zeroing has nothing to do with it. If there is no zeroing then there is an endless closure of orders and in my case one order is not closed.

 
EVGENII SHELIPOV #:

Yes, or a drawdown below a certain level. But as far as I understand zeroing has nothing to do with it, if there is no zeroing then there is an endless closure of orders and in my case one order is not closed.

This is because after the first order has been closed this condition does not work any more

if(CalculiteProfitMinMaxPenultimateOrders() >= 0 && OrderGroupCloseSignal()==0 &&
                  Drawdown >= DrawdownClosingMinMaxOrders && FindPenultimateProfit() > 0)

so it does not go further to the close function

 
Tretyakov Rostyslav #:

Because after the first order has been closed, this condition is no longer valid

that means it does not reach further, to the function of closing

Do you think that this condition is in the command to close orders and in the function to close orders if I remove this condition from the function to close orders will it change anything?

 
EVGENII SHELIPOV #:

Do you think this condition is in the command to close orders and in the function to close orders if I remove this condition from the function to close orders will it change anything

It will speed things up...why check the same thing twice.

By the way, you posted two different functions

ClosseMinMaxPenultimateOrdersZero()

и

ClosseMinMaxPenultimateOrders()
Is that the intention?
Reason: