初心者の方からの質問 MQL4 MT4 MetaTrader 4 - ページ 229

 
Aleksei Stepanenko:
ありがとうございます。他に解決策はありますか?その後、アドバイザーが取引を開始し、すぐに決済します。
 
Nargiz Ravanova:
ありがとうございます。他に解決策はありますか?その後、EAはポジションをオープンし、すぐにクローズします。

条件によって時間を固定する必要があります。

op>=Profit

で、ポジションがクローズ するまで更新しない。

で、現在時刻から記憶している時刻を引きます。
、指定した秒数が経過したら、ポジションを閉じます。

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

そうしました


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

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

}


が、エラーになります。


型変換によるデータ消失の可能

 

はエラーではなく、警告です。ある型から別の型に変換する際に、データが失われる可能性があります。

datetime time_waiting;
 
Nargiz Ravanova:

つまり、2銭と見てすぐにEAを閉じるのではなく、もう少し上げてほしいのです。

そして、10秒後には必ず利益が大きくなっているのはなぜか?)

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

もし差し支えなければ、修正にご協力ください...。
 
s = StringSetChar(s, lenght, ushort(symbol + 32));
string  StringSetChar(
   string&   string_var,       // строка
   int       pos,              // позиция
   ushort    value             // код символа
   );

全責任を負うこと

ユーソート

unsigned short型は ushort型で、これもサイズは2バイトである。最小値は0、最大値は65,535です。

イント

int型の サイズは4バイト(32ビット)である。最小値は-2 147 483 648、最大値は2 147 483 647です。

 
Iurii Tokman:

言われたとおりにしたのですが、CloseAll()関数の後に1時間のスリップがあるにもかかわらず、Expert Advisorを閉じた後になぜか数回のトレードが終了してしまうのです。

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

}.