Perguntas de Iniciantes MQL4 MT4 MetaTrader 4 - página 229

 
Aleksei Stepanenko:
Obrigado, existe alguma outra solução? O assessor então abre e imediatamente fecha o comércio.
 
Nargiz Ravanova:
Obrigado, existe outra solução? Depois disso, a EA abre e imediatamente fecha a posição.

você precisa fixar o tempo com a condição

op>=Profit

e não atualizá-lo até que a posição seja fechada

em seguida, subtraia do tempo atual o tempo que você memorizou
, quando os segundos dados tiverem passado, feche as posições.

 
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;
     }
  }
 

Eu o fiz


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

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

}


mas isso me dá um erro


possível perda de dados devido à conversão do tipo

 

não é um erro, mas um aviso: os dados podem ser perdidos ao se converter de um tipo para outro:

datetime time_waiting;
 
Nargiz Ravanova:

Ou seja, não quero que a EA feche tão logo eu veja 2 libras, mas um pouco mais.

E o que, sempre após 10 segundos o lucro é maior?)

 
Seguiu o exemplo MT4 "STRINGS: ASCII CHARACTERS TABELA E UTILIZAÇÃO"

//+------------------------------------------------------------------+
//| 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);
  }

Se você não se importa, por favor, ajude-me a consertá-lo...
 
s = StringSetChar(s, lenght, ushort(symbol + 32));
string  StringSetChar(
   string&   string_var,       // строка
   int       pos,              // позиция
   ushort    value             // код символа
   );

Aceitando plena responsabilidade pelo fato de que

ushort

O tipo curtonão assinado é o tipo ushort, que também tem um tamanho de 2 bytes. O valor mínimo é 0, o valor máximo é 65.535.

int

O tipo int inteiro tem um tamanho de 4 bytes (32 bits). O valor mínimo é de -2 147 483 648, o valor máximo é de 2 147 483 647.

 
Iurii Tokman:

Eu fiz como você disse, mas por alguma razão depois de fechar o Expert Advisor fecha alguns negócios, apesar do fato de eu ter um deslize de uma hora após a função CloseAll().

input int Second = 10;
datetime LastTime = 0;

void OnTick()

double op = CalculateProfit();


if (op >= Lucro && 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ão: