Domande dai principianti MQL4 MT4 MetaTrader 4 - pagina 229

 
Aleksei Stepanenko:
Grazie, c'è qualche altra soluzione? Il consulente quindi apre e chiude immediatamente il trade.
 
Nargiz Ravanova:
Grazie, c'è un'altra soluzione? Dopo di che l'EA apre e chiude immediatamente la posizione.

è necessario fissare il tempo sulla condizione

op>=Profit

e non aggiornarlo fino alla chiusura della posizione

poi sottrarre all'ora corrente il tempo che avete memorizzato
, quando i secondi dati sono passati, chiudere le posizioni.

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

L'ho fatto


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

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

}


ma mi dà un errore


possibile perdita di dati a causa della conversione del tipo

 

non è un errore, ma un avvertimento: i dati possono essere persi durante la conversione da un tipo all'altro:

datetime time_waiting;
 
Nargiz Ravanova:

Cioè, non voglio che l'EA si chiuda appena vedo 2 sterline, ma un po' di più.

E cosa, sempre dopo 10 secondi il profitto è maggiore?)

 
Seguito l'esempio 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);
  }

Se non ti dispiace, per favore aiutami a sistemarlo...
 
s = StringSetChar(s, lenght, ushort(symbol + 32));
string  StringSetChar(
   string&   string_var,       // строка
   int       pos,              // позиция
   ushort    value             // код символа
   );

Accettare la piena responsabilità del fatto che

ushort

Iltipo unsigned short è il tipo ushort, che ha anche una dimensione di 2 byte. Il valore minimo è 0, il valore massimo è 65.535.

int

Il tipo intero int ha una dimensione di 4 byte (32 bit). Il valore minimo è -2 147 483 648, il valore massimo è 2 147 483 647.

 
Iurii Tokman:

Ho fatto come hai detto tu, ma per qualche motivo dopo la chiusura l'Expert Advisor chiude un paio di trade, nonostante il fatto che ho uno slittamento di un'ora dopo la funzione CloseAll().

input int Second = 10;
datetime LastTime = 0;

void OnTick()

double op = CalculateProfit();


if (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

}

Motivazione: