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

 
Krokus:

Maybe so:

Other thoughts don't come...




You're reading between the lines. Anyway, look at what you put in the loop in the first place. The loop's action area...
 
Hello, in mt4 android for tablet need to download the terminal for each server separately ? login as on pc via file login is not possible ? Also, do you know if autoclick can be installed on an android tablet to trade in mt4 ?
 

Good afternoon! I can't get this condition to work:

OrderCloseTime()!=hour()

I want no more than one order to be opened in an hour!

All the same orders are opened!

 
lowech:

Good afternoon! I can't get this condition to work:

OrderCloseTime()!=hour()

I want no more than one order to be opened in an hour!

But all the same orders are opened! What can it be?

First of all: OrderCloseTime() - this is the time of order closing. If the order is not closed, it is equal to zero. You need to look at the time of opening.

Secondly: Hour() - this is the hour of start of the EA, and this hour does not change during the execution of the program. You need to compare it with the time of the last quote arrival - TimeCurrent()

This function returns the number of seconds after the last position of the current symbol was opened:

//+----------------------------------------------------------------------------+
datetime SecondsAfterOpenLastPos(int op, int mn) {
   datetime t=0;
   int      i, k=OrdersTotal();

   for (i=0; i<k; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderSymbol()!=Symbol())  continue;
         if (OrderType()!=op)          continue;
         if (OrderMagicNumber()!=mn)   continue;
         if (t<OrderOpenTime()) t=OrderOpenTime();
         }
      }
   return(TimeCurrent()-t);
}
//+----------------------------------------------------------------------------+

I.e., to check the number of seconds after the opening of the last Buy position with Magic, you need

if (SecondsAfterOpenLastPos(OP_BUY, Magic)>3600) {
   // Можно открывать следующий
   }
 
Hello, when you open the terminal again, after the weekend, all the charts, including the working charts with EAs, disappeared on a cent account. Instead of the chart there is a grey field, although the open positions, balance and funds were saved at the bottom. I had to re-download the terminal and re-install working charts with Expert Advisors. After that everything was OK. Please tell me what it is about and how can I eliminate this problem in the future in the most painless way?
 

First: OrderCloseTime() is the time to close the order. If the order is not closed, it is equal to zero. You need to watch the open time.

Second: Hour() - this is the hour of start of the Expert Advisor, and this hour does not change during the execution of the program. You need to compare it with the time of the last quote arrival - TimeCurrent()

This function returns the number of seconds after the last position of the current symbol was opened:

//+----------------------------------------------------------------------------+
datetime SecondsAfterOpenLastPos(int op, int mn) {
   datetime t=0;
   int      i, k=OrdersTotal();

   for (i=0; i<k; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderSymbol()!=Symbol())  continue;
         if (OrderType()!=op)          continue;
         if (OrderMagicNumber()!=mn)   continue;
         if (t<OrderOpenTime()) t=OrderOpenTime();
         }
      }
   return(TimeCurrent()-t);
}
//+----------------------------------------------------------------------------+

I.e., to check the number of seconds after the opening of the last Buy position with Magic, you need

if (SecondsAfterOpenLastPos(OP_BUY, Magic)>3600) {
   // Можно открывать следующий
   }
thank you for the function! don't you have another one?! so that only one order is opened per bar?!
 
lowech:
thank you for the feature! don't you have another one?! so that only one order opens per bar?!
//+----------------------------------------------------------------------------+
datetime BarsAfterOpenLastPos(int op, int mn) {
   datetime t=0;
   int      i, k=OrdersTotal();

   for (i=0; i<k; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderSymbol()!=Symbol())  continue;
         if (OrderType()!=op)          continue;
         if (OrderMagicNumber()!=mn)   continue;
         if (t<OrderOpenTime()) t=OrderOpenTime();
         }
      }
   return((TimeCurrent()-t)/60/Period());
}
//+----------------------------------------------------------------------------+

same thing, only check for the number of bars, not seconds

 
//+----------------------------------------------------------------------------+
datetime BarsAfterOpenLastPos(int op, int mn) {
   datetime t=0;
   int      i, k=OrdersTotal();

   for (i=0; i<k; i++) {
      if (OrderSelect(i, SELECT_BY_POS)) {
         if (OrderSymbol()!=Symbol())  continue;
         if (OrderType()!=op)          continue;
         if (OrderMagicNumber()!=mn)   continue;
         if (t<OrderOpenTime()) t=OrderOpenTime();
         }
      }
   return((TimeCurrent()-t)/60/Period());
}
//+----------------------------------------------------------------------------+

same thing, only check for number of bars, not seconds


It works! But when i close an order by TP, a new one will open right away!
 
Why aren't the trading layers displayed on the platform and why isn't the EA working?
 
lowech:

same thing, only check for the number of bars, not seconds


it works! But when an order closes on TP, a new one opens instantly! How can we fix it?

So we need to do another check: for the number of bars after the last order was closed:

//+----------------------------------------------------------------------------+
int BarsAfterCloseLastPos (int fi_MG, int fi_Type = -1)
{
    datetime ldt_Time = 0;
    int      li_Total = OrdersTotal();
//----
    for (int li_pos = 0; li_pos < li_Total; li_pos++)
    {
        if (!OrderSelect (li_pos, SELECT_BY_POS, MODE_HISTORY)) continue;
        if (OrderSymbol() != Symbol()) continue;
        if (fi_Type >= 0) if (OrderType() != fi_Type) continue;
        if (OrderMagicNumber() != fi_MG) continue;
        if (ldt_Time >= OrderCloseTime()) continue;
        ldt_Time = OrderCloseTime();
    }
    //---- Обрабатываем событие - отсутствие своих ордеров
    if (ldt_Time == 0) return (-1);
//----
    return (iBarShift (NULL, 0, ldt_Time));
}
//+----------------------------------------------------------------------------+
Reason: