跳至内容

TerminalClose

TerminalClose

此函数命令终端完成操作。

bool  TerminalClose(
   int ret_code      // closing code of the client terminal
   );

参数

ret_code

[in] 返回代码,由客户端终端在操作完成时返回。

返回值

如果成功,该函数返回 true;否则返回 false。

注意

TerminalClose() 函数不会立即停止终端,它只是命令终端完成其操作。

调用 TerminalClose() 的专家顾问代码必须确保所有先前打开的文件以正常模式关闭。调用此函数后必须执行 return 运算符

ret_code 参数允许指示启动终端操作时分析程序终止的原因所需的返回代码。

示例:

//--- input parameters
input int  tiks_before=500; // number of ticks till termination
input int  pips_to_go=15;   // distance in pips
input int  seconds_st=50;   // number of seconds given to the Expert Advisor
//--- globals
datetime   launch_time;
int        tick_counter=0;
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Print(__FUNCTION__," reason code = ",reason);
   Comment("");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   static double first_bid=0.0;
   MqlTick       tick;
   double        distance;
//---
   SymbolInfoTick(_Symbol,tick);
   tick_counter++;
   if(first_bid==0.0)
     {
      launch_time=tick.time;
      first_bid=tick.bid;
      Print("first_bid =",first_bid);
      return;
     }
//--- price distance in pips
   distance=(tick.bid-first_bid)/_Point;
//--- show a notification to track the EA operation
   string comm="From the moment of start:\r\n\x25CF elapsed seconds: "+
               IntegerToString(tick.time-launch_time)+" ;"+
               "\r\n\x25CF ticks received: "+(string)tick_counter+" ;"+
               "\r\n\x25CF price went in points: "+StringFormat("%G",distance);
   Comment(comm);
//--- section for checking condition to close the terminal
   if(tick_counter>=tiks_before)
      TerminalClose(0);    // exit by tick counter
   if(distance>pips_to_go)
      TerminalClose(1);    // go up by the number of pips equal to pips_to_go
   if(distance<-pips_to_go)
      TerminalClose(-1);   // go down by the number of pips equal to pips_to_go
   if(tick.time-launch_time>seconds_st)
      TerminalClose(100);  // termination by timeout
//---
  }

另请参阅

程序运行执行错误初始化失效的原因

最后更新于