Preguntas de los principiantes MQL4 MT4 MetaTrader 4 - página 229

 
Aleksei Stepanenko:
Gracias, ¿hay alguna otra solución? A continuación, el asesor abre y cierra inmediatamente la operación.
 
Nargiz Ravanova:
Gracias, ¿hay otra solución? Después, el EA abre y cierra inmediatamente la posición.

hay que fijar la hora en la condición

op>=Profit

y no se actualiza hasta que se cierra la posición

a continuación, reste a la hora actual el tiempo que ha memorizado
cuando hayan pasado los segundos indicados, cierre las posiciones

 
input int Second=10;
ulong LastTime=0;

void OnTick()
   {
   if(op>=Profit) LastTime=GetMicrosecondCount();
   if(LastTime>0 && GetMicrosecondCount()-LastTime>(ulong)Second*1000000) {CloseAll(); LastTime=0;}
   }
 
input int Second = 10;
datetime LastTime = 0;

void OnTick()
  {
   if(op >= Profit && LastTime == 0)
      LastTime = TimeCurrent();
   if(LastTime > 0 && TimeCurrent() - LastTime >= Second)
     {
      CloseAll();
      LastTime = 0;
     }
  }
 

Lo hice


double op = CalculateProfit();
int time_waiting=0;

if (op >= Profit)
time_waiting = TimeLocal() + 10;
if (TimeLocal() < time_waiting)
{
CloseAll();

}


pero me da un error


posible pérdida de datos debido a la conversión de tipos

 

no es un error, sino una advertencia: los datos pueden perderse al convertir de un tipo a otro:

datetime time_waiting;
 
Nargiz Ravanova:

Es decir, no quiero que el EA se cierre en cuanto vea 2 libras, sino un poco más.

¿Y qué, siempre después de 10 segundos el beneficio es mayor?)

 
Siguiendo el ejemplo de MT4 "STRINGS: ASCII CHARACTERS TABLE AND USE"

//+------------------------------------------------------------------+
//| StringLowerCase |
//+------------------------------------------------------------------+
string StringLowerCase(string str)
  {
   string s = str;
   int lenght = StringLen(str) - 1, symbol;
   while(lenght >= 0)
     {
      symbol = StringGetChar(s, lenght);
      if((symbol > 64 && symbol < 91) || (symbol > 191 && symbol < 224))
         s = StringSetChar(s, lenght, symbol + 32);// тут possible loss of data due to type conversion
      else
         if(symbol > -65 && symbol < -32)
            s = StringSetChar(s, lenght, symbol + 288);// тут possible loss of data due to type conversion
      lenght--;
     }
   return(s);
  }
//+------------------------------------------------------------------+
//| StringUpperCase |
//+------------------------------------------------------------------+
string StringUpperCase(string str)
  {
   string s = str;
   int lenght = StringLen(str) - 1, symbol;
   while(lenght >= 0)
     {
      symbol = StringGetChar(s, lenght);
      if((symbol > 96 && symbol < 123) || (symbol > 223 && symbol < 256))
         s = StringSetChar(s, lenght, symbol - 32);// тут possible loss of data due to type conversion
      else
         if(symbol > -33 && symbol < 0)
            s = StringSetChar(s, lenght, symbol + 224);// тут possible loss of data due to type conversion
      lenght--;
     }
   return(s);
  }

Si no te importa, por favor ayúdame a arreglarlo...
 
s = StringSetChar(s, lenght, ushort(symbol + 32));
string  StringSetChar(
   string&   string_var,       // строка
   int       pos,              // позиция
   ushort    value             // код символа
   );

Aceptar la plena responsabilidad por el hecho de que

ushort

El tipo unsigned short es el tipo ushort, que también tiene un tamaño de 2 bytes. El valor mínimo es 0, el valor máximo es 65.535.

int

El tipo entero int tiene un tamaño de 4 bytes (32 bits). El valor mínimo es -2 147 483 648, el valor máximo es 2 147 483 647.

 
Iurii Tokman:

Hice lo que me dijiste, pero por alguna razón después de cerrar el Asesor Experto cierra un par de operaciones, a pesar de que tengo un deslizamiento de una hora después de la función CloseAll().

input int Second = 10;
datetime LastTime = 0;

void OnTick()

double op = CalculateProfit();


si (op >= Profit && LastTime == 0)
LastTime = TimeCurrent ();
if(LastTime > 0 && TimeCurrent () - LastTime >= Second)

{
CloseAll();
LastTime = 0;

SendNotification("Trade is over");
Sleep(60*60000);// 60.000 = 1 min

}

Razón de la queja: