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

 
MakarFX #:
So what do you want anyway?)

I already did. Maybe a little sloppy. Correct me. I calculate the price of the last one first, followed by the penultimate one.
But there is another problem. Since control all Comment -ami in the corner, all the time if not involved hanging value equal to DBL_MAX. How to remove, highlighted in red)

double MinOpenSell() // ищу ордер по самой низкой цене.
{
   double oldticket, UpPrice = DBL_MAX;
   
   for(int cnt=OrdersTotal(); cnt>=0; cnt--)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
         {
            oldticket = OrderOpenPrice();
            if ( oldticket < UpPrice)
            {
               UpPrice = oldticket;
            }
         }
      }
   }
   return(UpPrice);
}
double FindPenultSellPrice() // а тут ищу предпоследний)
  {
   double oldticket, UpPrice = DBL_MAX;
   
   for(int cnt=OrdersTotal(); cnt>=0; cnt--)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
         {
            oldticket = OrderOpenPrice();
            if ( oldticket < UpPrice && MinOpenSell()< oldticket)
            {
               UpPrice = oldticket;
            }
         }
      }
   }
   return(UpPrice);
}
 
makssub #:

As the control is all Comment -ami in the corner, all the time if not engaged the value hangs equal to DBL_MAX. How to remove, highlighted in red)

put somewhere

if(price==DBL_MAX) price=0;

or it is possible directly in the comment:

(price==DBL_MAX)?"нет ордера":DoubleToString(price,_Point)
 
Taras Slobodyanik #:

put it somewhere

or you can put it directly in the comments:

I like the first option, can you give me an example of how to do it properly?

 
makssub #:

I like the first option, can you give me an example of how to do it properly?

double com_price=0;

if(UpPrice==DBL_MAX) com_price=0;
else com_price=UpPrice;

Comment(com_price);
 
MakarFX #:

thanks, but still don't understand how to screw it on) no criticism of my work?

double FindPenultSellPrice() // а тут ищу предпоследний)
  {
   double oldticket, UpPrice = DBL_MAX;
   
   for(int cnt=OrdersTotal(); cnt>=0; cnt--)
   {
      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL)
         {
            oldticket = OrderOpenPrice();
            if ( oldticket < UpPrice && MinOpenSell()< oldticket)
            {
               UpPrice = oldticket;
            }
         }
      }
   }
   return(UpPrice);
}
 
makssub #:

thanks, but still don't see how to screw it up) no criticism of my work?

Show me your comment.

 
MakarFX #:

Show me your comment.

I've posted a photo before. And my comment is not declared inside the function.

Comment( " Количество открытых ордеров: ", CountTrades(),"\n" " Количество открытых ордеров Sell: ", FindLastSell(), "\n" " Количество открытых ордеров Buy: ", FindLastBuy(),
                "\n" " Общее количество открытых ордеров: ", OrdersTotal(),"\n" " Профит первого ордера Sell: " , FirstProfitSell(),
                "\n" " Профит первого ордера Buy: " ,FirstProfitBuy(), "\n" " Предпоследний ордер Buy: ",FindPenultBuyPrice(), "\n" " Предпоследний ордер Sell: ",FindPenultSellPrice());  
 
makssub #:

I've posted a picture before. And the comment I have is not declared inside the function.

double com_price=0;
if(FindPenultSellPrice()==DBL_MAX) com_price=0;
else com_price=FindPenultSellPrice();
Comment( " Количество открытых ордеров: ", CountTrades(),"\n Количество открытых ордеров Sell: ", FindLastSell(),
       "\n Количество открытых ордеров Buy: ", FindLastBuy(),"\n Общее количество открытых ордеров: ", OrdersTotal(),
       "\n Профит первого ордера Sell: " , FirstProfitSell(),"\n Профит первого ордера Buy: " ,FirstProfitBuy(),
       "\n Предпоследний ордер Buy: ",FindPenultBuyPrice(), "\n Предпоследний ордер Sell: ",com_price);  
 

Good day all!!!

I'm writing code for an EA for Trailing Stop of group orders from the average price of a grid of orders.

No errors in the log, but the trawl does not work either. Here is the code please suggest where the error is. Thank you!!!

//+----------------------------------------------------------------------------+
//| Модификация групповых ордеров                                              |
//+----------------------------------------------------------------------------+
void ModifyOrders(int otype)
{
    double avg_price; 
    order_lots = 0;
    price = 0;
   
    for(int i = OrdersTotal()-1; i>=0; i--)
    {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
       {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
         {
            price += OrderOpenPrice() * OrderLots();
            order_lots += OrderLots() ;
         }
       }
    }
    avg_price = NormalizeDouble(price / order_lots, Digits);
     {
     ObjectDelete(0, "AveragePriceLine");
     ObjectCreate(0,"AveragePriceLine" ,OBJ_HLINE, 0, 0, avg_price);
     ObjectSet("AveragePriceLine",OBJPROP_COLOR, Magenta);
     }
    if (otype == OP_BUY) tp = NormalizeDouble (avg_price + TakeProfitGroupOrder*Point, Digits);
    if (otype == OP_SELL) tp = NormalizeDouble (avg_price - TakeProfitGroupOrder*Point, Digits);
    if ((otype == OP_BUY || otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero)) 
    tp = NormalizeDouble (avg_price, Digits);
    for(int i = OrdersTotal()-1; i>=0; i--) 
    {
       if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
       {
           if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype)
           {
               if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0))
                  Print("Ордера успешно модифицированы!");
                else Print("Ошибка модификации ордеров!");
                TrailingGroupOrder();
           }
       }
    }
}
//+----------------------------------------------------------------------------+
//| Трейлинг стоп групповых ордеров                                            |
//+----------------------------------------------------------------------------+
void TrailingGroupOrder()
{
    price += OrderOpenPrice() * OrderLots();
    order_lots += OrderLots() ;
    for(int i = OrdersTotal()-1; i>=0; i--)
    {
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
       {
       if(OrderType() == OP_BUY && Bid - NormalizeDouble(price / order_lots, Digits) > TrailingStopGroupOrder)
        {
        if(Bid - NormalizeDouble(price / order_lots, Digits) > TrailingStopGroupOrder*Point || OrderStopLoss() == 0)
         {
         if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder )*Point || OrderStopLoss() == 0)
          {
          if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStopGroupOrder*Point, Digits), tp, 0))
                    Print("Ошибка модификации групповых ордеров на покупку!");
          }
         }
        }
        if(OrderType() == OP_SELL && NormalizeDouble(price / order_lots, Digits)- Ask > TrailingStopGroupOrder*Point)
         {
         if( NormalizeDouble(price / order_lots, Digits)- Ask > TrailingStopGroupOrder*Point || OrderStopLoss() == 0)
           {
            if(OrderStopLoss() > Ask + (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0)
              {
              if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStopGroupOrder*Point, Digits), tp, 0))
                    Print("Ошибка модификации групповых ордеров на продажу!");
              }
           }
         }
      } 
    }
}
 
Good afternoon! Where can I find the mql4 code to change the language in the EA settings window?
Reason: