[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 111

 
sergeev:

How can a pro answer it, if it is not a full TOR.

If it's a checkmate - well then put return from the loop where you delete/close orders.

And if you go....

https://www.mql5.com/ru/code/10672
 

Don't scare me.

I wrote the answer to your verbatim question "How to make this EA not close orders in batches".

- If you want this EA not to close orders in batches, you should return from the close order loop after the first close.

Does this work?

 
Solree:
Can you explain it in more details? A piece of code with it, if you don't mind :)

These are snippets of code to set the vertical sweep of the indicator subwindow.

  // Для буфера развёртки по вертикали.
  SetIndexBuffer(0, gl_adBufIndicator1);               // Индикаторный буфер для стабилизации и размера изображения графика в дополнительном подокне.
  SetIndexEmptyValue (0, EMPTY_VALUE);                 // Устанавливаем значение пустой величины для линии индикатора.
  SetIndexLabel(0, "VERTICAL SWEEP");                  // Установка имени линии индикатора для отображения информации в окне DataWindow и всплывающей подсказке.
  SetIndexStyle(0, DRAW_NONE, EMPTY, EMPTY, CLR_NONE); // Линию не показываем.
  //==== Устанавливаем развёртку.
  if (st_nWBeginChart <= 0) st_nWBeginChart = 0;
  for (i = st_nWFirstVisiblBar; i >= st_nWBeginChart; i--)
   {// Очищаем буфер от лишних значков для вызова окна свойств индикатора.
    if (i > 0) gl_adBufIndicator2[i] = EMPTY_VALUE;
    // Закрепление вертикальной развёртки графика с помощью индикаторного буфера.
    if (i % 2 == 0) gl_adBufIndicator1[i] = gl_dMaxPositionMark; // Для фиксации верхней координаты дополнительного окна.
    else gl_adBufIndicator1[i] = gl_dMinPositionMark;            // Для фиксации нижней координаты дополнительного окна.
   }
  //==== Расчёт и создание горизонтальных линий разметки.
  if ((gl_dMaxPositionMark - gl_dMinPositionMark) != tmp_dDifferPosMark) // Создаём один раз и отслеживаем через заданный уровень при увеличениях максимальных уровней.
   {// Расчёт и создание горизонтальных линий разметки.
    MakingHorizontalSectoring(AutoStep, Color_LNH, Color_LN0, gl_dMaxPositionMark, gl_dMinPositionMark, Step_LNH, 15, Style_LNH, Width_LNH, st_nWindow, gl_sFullNameObject);
   }

This is the function to set the horizontal lines. The function only works from the indicator code. It does not work from the library.

// 2. Функция расчёта и создания горизонтальных линий разметки.
void MakingHorizontalSectoring(bool   bAutoStep, // Переключатель true/fals = автоматическое/ручное распределение уровней.
                               color  clLine,    // Цвет уровней.
                               color  clLine0,   // Цвет нулевого уровня.
                               double dScaleMAX, // Максимальное значение шкалы.
                               double dScaleMIN, // Минимальное значение шкалы.
                               double dStepH,    // При AutoStp = true/false - количество линий/растояние между линиями.
                               int    nLimiter,  // Ограничение десятичных разрядов в вычислениях порядка амплитуды.
                               int    nStyle,    // Стиль уровней.
                               int    nWidth,    // Толщина уровней.
                               int    nWindow,   // Номер подокна для создания нулевой линий.
                               string sName)     // Имя для индивидуального имени нулевой горизонтальной линии.
 {
  double dStepLN = 0;
  int    nExponent = 0;
  int    i = 0, j = 0, n = 0;
  int    nLowLevel = 0;
  int    nStep = 0;
  int    nUpLevel = 0;
  //----
  if (1000000 * dStepH != 0)
   {
    if (bAutoStep == true) // Автоматическая установка горизонтальных линий по заданному количеству линий по вертикали.
     {
      dStepLN = (dScaleMAX - dScaleMIN) / dStepH; // Считаем шаг в виде числа двойной точности.
      // Вычисление порядка исходного десятичного числа.
      if (dStepLN * MathPow(10, nLimiter) != 0)   // Если число меньше единицы. Проверяем на равенство первому разряду.
       {
        if (dStepLN < 1)
         {
          for (nExponent = 0; nExponent <= nLimiter; nExponent++)
           {
            i = dStepLN * MathPow(10, nExponent);
            if (i >= 1) break;
           }
         }
        if (1 <= dStepLN && dStepLN < 10) nExponent = 0; // Если число между единицей и десятью. Возвращаем нулевой порядок.
        if (dStepLN >= 10)                               // Если число больше или равно единицы. Проверяем на равенство первому разряду.
         {
          for (nExponent = 0; nExponent >= -nLimiter; nExponent--)
           {
            i = dStepLN * MathPow(10, nExponent);
            if (i <= 9) break;
           }
         }
       }
      else nExponent = 0;                                  // Если число с заданной точностью равно нулю.
      nStep = MathRound(dStepLN * MathPow(10, nExponent)); // Преобразум шаг в целое число и окруляем его.
      switch (nStep)                                       // Приводим к стандартному шагу.
       {
        case 1:  nStep =  2; break;
        case 2:  nStep =  2; break;
        case 3:  nStep =  2; break;
        case 4:  nStep =  5; break;
        case 5:  nStep =  5; break;
        case 6:  nStep =  5; break;
        default: nStep = 10;
       }
      dStepLN = nStep * MathPow(10, -nExponent);
      nUpLevel  = (dScaleMAX - MathMod(dScaleMAX, dStepLN)) / dStepLN + 1; // Верхняя граница шкалы для отсчёта шага.
      nLowLevel = (dScaleMIN - MathMod(dScaleMIN, dStepLN)) / dStepLN - 1; // Нижняя граница шкалы для отсчёта шага.
      for (j = nUpLevel; j >= nLowLevel && 1000000 * dStepLN > 0; j--, i++) if (j != 0) SetLevelValue (i, j * dStepLN);
      i++;
      for (n = i; n <= 31; n++) SetLevelValue(n, (j + 1) * dStepLN); // Собираем оставшиеся уровни на последней координате, чтобы не мешались.
     }
    else // Ручная установка горизонтальных линий по заданному шагу по вертикали.
     {
      nUpLevel  = (dScaleMAX - MathMod(dScaleMAX, dStepH)) / dStepH + 1; // Верхняя граница шкалы для отсчёта шага.
      nLowLevel = (dScaleMIN - MathMod(dScaleMIN, dStepH)) / dStepH - 1; // Нижняя граница шкалы для отсчёта шага.
      for (j = nUpLevel; j >= nLowLevel && 1000000 * dStepH > 0; j--, i++) if (j != 0) SetLevelValue(i, j * dStepH);
      i++;
      for (n = i; n <= 31; n++) SetLevelValue(n, (j + 1) * dStepLN); // Собираем оставшиеся уровни на последней коордиеате, чтобы не мешались.
     }
   }
  SetLevelStyle(nStyle, nWidth, clLine);
  // Удаляем горизонтальную нулевую линию.
  ObjectDelete(sName + " HLINE 0");
  // Создаём объект "HLINE 0". Этот объект создаётся всегда.
  ObjectCreate(sName + " HLINE 0", OBJ_HLINE, nWindow, 0, 0);
  ObjectSet   (sName + " HLINE 0", OBJPROP_COLOR, clLine0);
  ObjectSet   (sName + " HLINE 0", OBJPROP_STYLE, nStyle);
  ObjectSet   (sName + " HLINE 0", OBJPROP_WIDTH, nWidth);
 }

You are on your own with drawing by graphical objects. Everything is individual.

 
sergeev:

Don't be intimidated.

I wrote the answer to your verbatim question "How to stop this EA from closing orders in batches?

- If you want this EA not to close orders in batches, you should return them from the order closing loop after the first closing.

Does this work?

you see the return is already in the order closing loop. Where to look for the first order closing ?

int CloseOrder(int ticket, double lots)
              {
               int err,i1;
               double price;
               OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES);
               if (lots<MarketInfo(Symbol(),MODE_MINLOT))lots=MarketInfo(Symbol(),MODE_MINLOT);
               while(i1<10)
                   {
                    RefreshRates();
                    if (OrderType()==0)price=Bid;
                    if (OrderType()==1)price=Ask;
                    if (OrderType()>1){OrderDelete(ticket);return(0);}
                    OrderClose(ticket,lots,NormalizeDouble(price,Digits),Slippage,Goldenrod);
                    err = GetLastError();
                    if (err == 0) break;
                    Print(WindowExpertName(),Symbol(),Error(err),"  при закрытии ордера");
                    Sleep(100);
                    i1++;
                   }
               return(0);
              }
 
alex12:

here you see return is already standing in the order closing loop. Where to look for the first order closure exactly ?


This is not an order loop.

this is a stubborn retry for one order.

keep looking

 
sergeev:

it is not an order cycle.

it's a stubborn over-run for a single order.

keep looking

I put the return in here. Right ?

/////////////////////////////////////////////////////////////////////////
int CloseMarket()
   {
    for (int j=0; j<OrdersTotal(); j++)
      {
       OrderSelect(j,SELECT_BY_POS,MODE_TRADES);
       if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()<2)
         {
          CloseOrder(OrderTicket(),OrderLots());
          j--;
          return(0);
         }
      }
   }
/////////////////////////////////////////////////////////////////////////////
 
alex12:

so I put the return in here. Right ?


What do you think?

it's strange to see you in this thread at all, someone with publications in the codebase.

 

guys, how do i make a code to modify an order to breakeven.

we need to make the stop move 1 pips to the plus side and not touch it again.

my way

               switch(Tip)
                  {
                   case 0:
                     if(Ask>op+ts*Point)sl=op+d*Point;
                     break;
                   case 1:
                     if(Bid<op-ts*Point)sl=op-d*Point;
                  }

               OrderModify(Ticket,op,sl,takeprofit,0);

it looks like the order should be modified each time the condition is true.

ps.

            ts=300,     //-- ts - трейлинг
            d=10;       //-- d - на 'd' пп передвинуть в безубыток     


 
sergeev:

What do you think?

I think it's strange to see you in this thread, someone who has published articles in codebase.

Tested and the result - opened 2 orders and didn't close on profit and didn't open any more.

So this variant is not suitable.

I have published my ideas in the codebase and my Expert Advisors have been written to my order by experienced programmers.

I give up - I don't know where to put return, I've tried it everywhere.

 
Zhunko:

These are snippets of code to set the vertical sweep of the indicator subwindow.

This is the function to set the horizontal lines. The function only works from the indicator code. It does not work from the library.

You are on your own with drawing by graphical objects. Everything is individual.

Thanks, I'll try to figure it out :)