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

 
Valeriy Yastremskiy #:
First, the difference is 1000 before the cycle. In the loop, if the opening price minus the current price is modulo less than the difference, then the difference is equal to the obtained value and the ticket is stored in a variable.

I was thinking the same thing) But something went wrong. Can you give me an example of how to track the opening price of the closest order to the current price online. Or maybe just compare them, and look for the lowest price)

double FindSellOpen() 

{
   int oldticket;
   double oldopenprice=0;
   ticket=0;
   double Dist=1000000.0;
   
   for(int i=1; i<=OrdersTotal(); i++) 
   {
      if (OrderSelect(i-1,SELECT_BY_POS)==true)
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
         {
            oldticket = OrderTicket();
            if (NormalizeDouble(MathAbs(oldticket),Digits) < NormalizeDouble(Dist,Digits)) 
            {
               ticket = oldticket;
               oldopenprice = OrderOpenPrice();
            }
         }
      }
   }
   return(oldopenprice);
}
 
makssub #:

I was thinking the same thing) But something went wrong. Can you give me an example of how to track the opening price of the closest order to the current price online. Or maybe just compare them and look for the lowest price)

Take a look at this:

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 05.06.2008                                                     |
//|  Описание : Возвращает тикет ближайшей к рынку позиции по цене открытия.   |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (""   - любой символ,                   |
//|                                     NULL - текущий символ)                 |
//|    op - операция                   (-1   - любая позиция)                  |
//|    mn - MagicNumber                (-1   - любой магик)                    |
//+----------------------------------------------------------------------------+
int TicketNearPos(string sy="", int op=-1, int mn=-1) {
  double mi, p;
  int    i, k=OrdersTotal(), pp=0, ti=0;

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (OrderType()==OP_BUY)  mi=MarketInfo(OrderSymbol(), MODE_ASK);
            if (OrderType()==OP_SELL) mi=MarketInfo(OrderSymbol(), MODE_BID);
            p=MarketInfo(OrderSymbol(), MODE_POINT);
            if (p==0) if (StringFind(sy, "JPY")<0) p=0.0001; else p=0.01;
            if (pp==0 || pp>MathAbs(OrderOpenPrice()-mi)/p) {
              pp=MathAbs(OrderOpenPrice()-mi)/p;
              ti=OrderTicket();
            }
          }
        }
      }
    }
  }
  return(ti);
}
 
MakarFX #:

correct this as well.

MakarFX #:

No need to multiply MODE_SPREAD - Spread in pips

you can check it.

and make it so

Good day Makar!

If you want to understand the logic of closing min and max orders, you've got two parts of the code. In words, it sounds like this: "If the drawdown of a grid of orders exceeds a certain level, we close min and max orders in the grid, with a profit not less than the specified level" .

Then "If the drawdown has fallen below the set level, we return to the principle of averaging of orders, all orders with a profit by all orders with a loss".

Then "If the drawdown has not decreased below the set level, we close again the next min and max orders when the profit is reached".

Now the Expert Advisor understands that if the drawdown is exceeded, the min and max orders are taken - the EA closes the first pair as it should, but it closes all other pairs at the same price without paying attention to profit calculation.

As far as I understand, I should look through the OrderClose()function to stop it in time. Thanks in advance for the help!!!!

if (CountTrade() < MaxOrders)                                                           
       {
           int order_type = FindLastOrderType();
           if (order_type == OP_BUY)
           { 
              price = FindLastOrderPrice(OP_BUY);  
              if(Ask<= price - Step()*Point)
              {
                  lastlot = NormalizeDouble(GetMinLotOrder()*MathPow( MultiplierParameter, OrdersTotal()), 2);
                  ticket = OrderSend(Symbol(), OP_BUY, lastlot, Ask, slip, 0, 0, "Групповой ордер", Magic, 0, Blue);
                  if (ticket < 1)
                      Print ("Ошибка ордера на покупку");
                  ModifyOrders(OP_BUY);
              }
           }
             if (order_type == OP_SELL)
           { 
              price = FindLastOrderPrice(OP_SELL);  
              if(Bid>= price + Step()*Point)
              {
                  lastlot = NormalizeDouble(GetMinLotOrder()*MathPow( MultiplierParameter, OrdersTotal()), 2);
                  ticket = OrderSend(Symbol(), OP_SELL, lastlot, Bid, slip, 0, 0, "Групповой ордер", Magic, 0, Red);
                  if (ticket < 1)
                      Print ("Ошибка ордера на продажу!");
                  ModifyOrders(OP_SELL);
              }
           }
         } 
         double op = CalculiteProfit(); 
         if (op > ProfitMinMaxOrders && Drawdown > DrawdownClosingMinMaxOrders)
           {
           ClosseMinMaxOrders();
           } 

//+----------------------------------------------------------------------------+
//| Калькуляция профита максимального и минимального ордера в сетке            |
//+----------------------------------------------------------------------------+
double CalculiteProfit()
{
    double AmountMinMaxProfit = 0;
    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 || OrderType() == OP_SELL)
          {
            AmountMinMaxProfit = GetProfitMinOrder() + GetProfitMaxOrder();
          }
        }
      }
    }
    return(AmountMinMaxProfit);
}
//+----------------------------------------------------------------------------+
//| Закрытие минимального и максимального ордеров                              |
//+----------------------------------------------------------------------------+
void  ClosseMinMaxOrders()
{
  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 (OrderClose(GetTicketMinOrder(), GetMinLotOrder(), Bid, slipp) && OrderClose(GetTicketMaxOrder(), FindLastLots(), Bid, slipp))
            Print("Максимальный и минимальный ордера на покупку успешно закрыты!");
         else
              Print("Не удалось закрыть максимальный и минимальный ордера на покупку!",GetLastError());
          }   
   
        if (OrderType() == OP_SELL)
         {
        if (OrderClose(GetTicketMinOrder(), GetMinLotOrder(), Ask, slipp) && OrderClose(GetTicketMaxOrder(), FindLastLots(), Ask, slipp))
            Print("Максимальный и минимальный ордера на продажу успешно закрыты!");
         else
              Print("Не удалось закрыть максимальный и минимальный ордера на продажу!",GetLastError());
         }
       } 
     }
  }
}


 
Good afternoon! Sorry for the primitive question, but where can I find the contact details of the EA's tenant? Or how do I contact the person who bought/rented the EA?
 
Oleksandr Nozemtsev #:
Hi, sorry for the primitive question, but where can I find the contact details of the EA's tenant? Or how do I contact the person who has bought/rented an EA?

You can't. You can have a dialogue in the Product Discussion tab. You can post news in the relevant tab.

 
Vladimir Karputov #:

You can't. You can have a dialogue in the Product Discussion tab. You can post news in the appropriate tab.

Thank you!

 
Good afternoon.
Can you tell me where to clean the quotes in mt 5?
And is it possible not to erase all of them, but only the ancient ones?
 
Roman Kutemov #:
Good afternoon.
Can you tell me where to clean the quotes in mt 5?
And is it possible not to erase all of them, but only the ancient ones?
C:\MetaTrader5\bases\MetaQuotes-Server\history
 
EVGENII SHELIPOV #:

Good day Makar!!!

I gave you another function...no need to add anything

//+----------------------------------------------------------------------------+
//| Закрытие минимального и максимального ордеров                              |
//+----------------------------------------------------------------------------+
void  ClosseMinMaxOrders()
{
  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 (OrderClose(GetTicketMinOrder(), GetMinLotOrder(), Bid, slipp) && OrderClose(GetTicketMaxOrder(), FindLastLots(), Bid, slipp))
            Print("Максимальный и минимальный ордера на покупку успешно закрыты!");
         else
            Print("Не удалось закрыть максимальный и минимальный ордера на покупку!",GetLastError());
       } 
     }
  }
}

Or you can move it...

//+----------------------------------------------------------------------------+
//| Закрытие минимального и максимального ордеров                              |
//+----------------------------------------------------------------------------+
void  ClosseMinMaxOrders()
{
  int slipp = (int) MarketInfo(_Symbol,MODE_SPREAD)*2;
  if (CalculiteProfit() > ProfitMinMaxOrders && Drawdown > DrawdownClosingMinMaxOrders)
  {   
     for(int i = OrdersTotal()-1; i>=0; i--)
     {
        if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
        {
          if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
           {
            if (OrderClose(GetTicketMinOrder(), GetMinLotOrder(), Bid, slipp) && OrderClose(GetTicketMaxOrder(), FindLastLots(), Bid, slipp))
               Print("Максимальный и минимальный ордера на покупку успешно закрыты!");
            else
               Print("Не удалось закрыть максимальный и минимальный ордера на покупку!",GetLastError());
          } 
        }
     }
  }   
}
 
MakarFX #:

I gave you another function...no need to add anything

or you can move it...

Nothing has changed