TerminalClose

该函数命令服务器完整操作。

bool  TerminalClose(

   int ret_code      // 关闭客户端代码

   );

参量

ret_code

[in]  返回代码,在操作完成后通过客户端返回。

返回值

函数成功true,否则-false。

注释

TerminalClose() 函数并不能立即阻止客户端,它只命令客户端完成操作。

EA交易的代码叫做TerminalClose(),它来执行立即操作(比如,所有先前开放文件在正常模式下都要先关闭),该函数的调用通过 返回操作符执行。

ret_code 参数程序分析原因返回的必要代码,在命令提示符启动后,客户端操作终止

示例:

//--- 输入参量

input int  tiks_before=500; // 订单号数目直到终止

input int  pips_to_go=15;   //  pips 间的距离

input int  seconds_st=50;   // 给予EA交易的秒数

//--- 全局

datetime   launch_time;

int        tick_counter=0;

//+------------------------------------------------------------------+

//| 专家无法初始化函数                                                  |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

//---

   Print(__FUNCTION__," reason code = ",reason);

   Comment("");

  }

//+------------------------------------------------------------------+

//| 专家订单号函数                                                     |

//+------------------------------------------------------------------+

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;

     }

//---  pips 的价格距离

   distance=(tick.bid-first_bid)/_Point;

//--- 通过EA操作显示告示

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

//--- 检测关闭程序端状态的部分

   if(tick_counter>=tiks_before)

      TerminalClose(0);    // 推出订单号计数器

   if(distance>pips_to_go)

      TerminalClose(1);    // 同于pips_to_go增长pips数量

   if(distance<-pips_to_go)

      TerminalClose(-1);   // 同于pips_to_go下降pips的数量

   if(tick.time-launch_time>seconds_st)

      TerminalClose(100);  // 超时终止

//---

  }

另见

程序运行执行错误无法初始化原因