Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 123

 
hoz:


Yes, by the way, this arrangement is more intelligent in implementation. The associated function at the start is now taking up more space. It turned out like this:

There's nothing to optimise, is there?

I mean that it's much more convenient, when there is not much at all in the start. And everything is called purely by functions. And last time it turned out that the start has all sorts of nesting of main functions and overloading of additional ones...

And why pass an array by reference, if you're using a globally declared array name in a function? Maybe you should do it that way:

void FindOrders(int &massive[])
{
   int oType;
   ArrayInitialize(massive, 0);
   for (int i=OrdersTotal() - 1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      
      oType = OrderType();
      massive[oType] = massive[oType] + 1;
   }
}

And you can cut it down a little bit:

void FindOrders(int &massive[])
{
   ArrayInitialize(massive, 0);
   for (int i=OrdersTotal() - 1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      
      massive[OrderType()] = massive[OrderType()] + 1;
   }
}

And what about calling from start and displaying messages. It seems to me that they messed up something. We cannot see the pr() function, so we have nothing to suggest.

I checked the number of orders in the tester using a quick algorithm:

   FindOrders(mn0, OrdersMassive);

   Comment ("\n"+"Всего ордеров = "+OrdersTotal()+
            "\n"+"Количество "+GetNameOP(0)+" = "+OrdersMassive[0]+
            "\n"+"Количество "+GetNameOP(1)+" = "+OrdersMassive[1]+
            "\n"+"Количество "+GetNameOP(2)+" = "+OrdersMassive[2]+
            "\n"+"Количество "+GetNameOP(3)+" = "+OrdersMassive[3]+
            "\n"+"Количество "+GetNameOP(4)+" = "+OrdersMassive[4]+
            "\n"+"Количество "+GetNameOP(5)+" = "+OrdersMassive[5]
            );

You can wrap the entire output in a function that will read data from the array and display the information in a human way.

 
nick_travel:

Good day!

Please help and explain why the EA does not work or trades?


Because here. not all telepaths and not all and visionaries!
 

I see!

I mean, is there a setting or something else you need?

 
artmedia70:

Why pass an array by reference if you use a globally declared array name in the function? Maybe it should be that way:

void FindOrders(int &massive[])
{
   int oType;
   ArrayInitialize(massive, 0);
   for (int i=OrdersTotal() - 1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      
      oType = OrderType();
      massive[oType] = massive[oType] + 1;
   }
}

Actually, yes, it makes sense. But you pass it by reference here, too:)) I had it after last time, when parameters were not declared globally.

And about the pr function. Here it is:

//+-------------------------------------------------------------------------------------+
//| Распринтовка на экран                                                               |
//+-------------------------------------------------------------------------------------+
void pr (string txt)
{
   string info [];
   ArrayResize(info, 20);
   string h, m, s, cm; int i;
   
   h = DoubleToStr(Hour(), 0);    if (StringLen(h) < 2) h = "0" + h;
   m = DoubleToStr(Minute(), 0);  if (StringLen(m) < 2) m = "0" + m;
   s = DoubleToStr(Seconds(), 0); if (StringLen(s) < 2) s = "0" + s;
   txt = h + ":" + m + ":" + s + " - " + txt;
   
   for (i=20-1; i>=1; i--)
   info[i] = info[i-1];
   info[0] = txt;
   
   for (i=20-1; i>=0; i--)
   if (info[i] != "")
   {
      cm = info[i];
      ObjectCreate ("txtw"+i, OBJ_LABEL, 0, 0, 0);
      ObjectSet    ("txtw"+i, OBJPROP_CORNER, 1);
      ObjectSet    ("txtw"+i, OBJPROP_XDISTANCE, 10);
      ObjectSet    ("txtw"+i, OBJPROP_YDISTANCE, 30+15*i);
      ObjectSetText("txtw"+i, cm, 10, "Times New Roman", Green);
   }
}
 
nick_travel:

I see!

I mean, is there a setting or something else you need?


I mean, I don't think there are any telepaths here, and even if there are, just try to interest them in such a feat... Guess and help...

 
hoz:


I mean, there's hardly any telepaths around here, and even if there are, you'd better try to get them interested in such feats... Guess and help...

And maybe a very good system that does not allow the wrong entry into the market! I wish I had one!
 

I am having an ongoing stoppage in the closing of required positions. The bottom line is this:

1. the closing of positions is being tracked.

2. As soon as the last position has closed on the takeaway... ...all open and pending positions should be closed at once. Everything is closed sorted by lots, i.e. large lots at once, and then smaller. This is intended only for gaining experience with orders.

The implementation is as follows:

In start() on every tick:

 for (int ord=OrdersTotal()-1; ord>=0; ord--)
   {
      if (!OrderSelect(ord,SELECT_BY_POS)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() == 6) continue;
        
      g_ticket = OrderTicket();
      g_type = OrderType();
              
      // Блок модификации ордеров       
      if (i_sl != 0 || i_tp != 0)
      {
         if (OrderStopLoss() == 0 && OrderTakeProfit() == 0)
         {
            OrdersModifyer(g_ticket);
         }
      }
      // Закрытие всех ордеров, если последний ордер закрыт
      if (isCloseByTakeLastOpenPos(2))
      {
         // if (g_type < 2)
          {
              ClosePosBySortLots();
          }
          //else
          if (g_type > 1)
          {
              DeletePendingOrders(g_ticket);
          }
      }
   }

We are interested in closing market orders since the pending one is deleted as required. Here is what we have:

//+-------------------------------------------------------------------------------------+
//| Получаем состояние последней позиции (Открыта или закрыта)                          |
//+-------------------------------------------------------------------------------------+
bool isCloseByTakeLastOpenPos(int delta)
{
   datetime lastOrderCloseTime = -1,               // Время закрытия последнего открытого ордера
            lastOOTHist = -1;                     // Время открытия последнего открытого ордера из истории
   int j = -1;
   pr ("Запустилась функция isCloseByTakeLastOpenPos");
   
   for (int i=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() > 1) continue;               // Все удалённые отложки нас не интересуют..
  
      if (lastOrderCloseTime < OrderCloseTime())   // Находим время закрытия..
      {
         lastOrderCloseTime = OrderCloseTime();   // ..последней закрытой позиции в истории
         j = i;
         pr ("j = " + j + "   " + TimeToStr(TimeCurrent()));
      }
   }
  if (OrderSelect(j, SELECT_BY_POS, MODE_HISTORY))
   {
      if (OrderProfit() + OrderCommission() + OrderSwap() <= 0) return (false);
//      pr ("OTP() = " + OrderTakeProfit() + "; OCP() " + OrderClosePrice() + "   " + TimeToStr(TimeCurrent()));
  //    pr ("OOP() = " + OrderOpenPrice() + "; OCP() " + OrderClosePrice() + "   " + TimeToStr(TimeCurrent()));
      if (MathAbs(OrderTakeProfit() - OrderClosePrice()) > delta * pt) return (false);
      else
      {
         lastOOTHist = OrderOpenTime();
         Comment("\n", "FUNC isCloseByTakeLastOpenPos: ",
                 "\n", "j = ", j,
                 "\n", "lastOOTHist = ", TimeToStr(lastOOTHist, TIME_SECONDS));
      }
   }
   else
   {
      Comment("\n", "FUNC isCloseByTakeLastOpenPos: ",
              "\n", "j = ", j,
              "\n", "не удалось выбрать ордер в истории");
      return(false);
   }
  
   for(int h=OrdersTotal()-1; h>=0; h--)
   {
      if (OrderSelect(h, SELECT_BY_POS, MODE_TRADES))
      {
         if (OrderMagicNumber() != i_magic)   continue;
         if (OrderSymbol() != Symbol())       continue;
         if (OrderType() > 1)                 continue;
         if (lastOOTHist < OrderOpenTime()) return(false);  // Выбранная рыночная позиция открыта позже закрытой по тейку
      }
      else {Print("FUNC isCloseByTakeLastOpenPos : не удалось выбрать рыночный ордер");return(false);}
   }
   
   return (true);
}

//+-------------------------------------------------------------------------------------+
//| Закрытие ордеров, отсортированных по размеру лотов                                  |
//+-------------------------------------------------------------------------------------+
void ClosePosBySortLots()
{
   double a[][2];
   int p = 0;
   
   for (int i=OrdersTotal()-1; i>=0; i--)
   {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderType() < 2)
      {
         p++;
         ArrayResize(a, p);
         a[p-1][0] = OrderLots();
         a[p-1][1] = OrderTicket();
      }
   }
   pr ("ClosePosBySortLots(): " + "p = " + p);
   if (p > 0)
   {
      ArraySort(a, WHOLE_ARRAY, 0, MODE_DESCEND);
      for(i=0; i<p; i++)
      {
         if (OrderSelect(a[i][1], SELECT_BY_TICKET, MODE_TRADES))
         {
             if (OrderCloseTime() == 0) ClosePosBySelect();
         }
      }
   }
}
//+-------------------------------------------------------------------------------------+
//| Закрытие одного, предварительно выбранного ордера                                   |
//+-------------------------------------------------------------------------------------+
void ClosePosBySelect()
{
   bool   fc;
   color  clClose, clCloseBuy = Blue, clCloseSell = Red;
   double ll, pa, pb, pp;
   int    err, it, NumberOfTry = 3;

   if (OrderType() == OP_BUY || OrderType() == OP_SELL)
   {
       for (it=1; it<=NumberOfTry; it++)
       {
           while (!IsTradeAllowed()) Sleep(5000);
           RefreshRates();
           pa = MarketInfo(OrderSymbol(), MODE_ASK);
           pb = MarketInfo(OrderSymbol(), MODE_BID);
           if (OrderType() == OP_BUY)
           {
               pp = pb; clClose = clCloseBuy;
           }
           else
           {
               pp = pa; clClose = clCloseSell;
           }
           ll = OrderLots();
           fc = OrderClose(OrderTicket(), ll, pp, 30, clClose);
           if (fc)
           {
              break;
           }
           else
           {
               err = GetLastError();
           }
       }
   }
   else Print("Некорректная торговая операция. Close ");
}

For some reason some of the orders are not being closed. I print some segments when I see them, I don't understand anything. Here is an example:

The comment shows that lastOOTHist = 01:30:00, though this is not actually correct. If we check lastOOTHist in the results window, we will see that

their closing times are different...

What is wrong here?

 
hoz:

Actually, yes, it makes sense. You also have a link here...:)) I had this left over from last time, when the parameters were not global.

I argued that the array here should be passed by reference. Otherwise, the function is doomed to work with only one, hardcoded array. Even if you have it defined globally.
 

Sorry to be needed at the end of the week, but I'll ask.

Does anyone have any experience of reading a message on a mailbox from a known sender?

 
ikatsko:

Sorry to be needed at the end of the week, but I'll ask.

Does anyone have any experience of reading a message on a mailbox from a known sender?

I've done this, set up the mail sorter by incoming address and sabject to throw a text file in the terminal directory, and there the advisor waits for the text file, processes it and deletes it.
Reason: