ExpertRemove
ExpertRemove
函数停止 EA交易 并从图表中卸载。
void ExpertRemove();返回值
没有返回值。
注释
一旦调用ExpertRemove()函数,EA交易不会立即停止,设立一个停止EA操作的标志,任何事件都不能处理,调用 OnDeinit() ,然后EA交易就会卸载并且从图表中删除。
在OnInit()处理程序内的策略测试中调用ExpertRemove()取消对当前参数集的测试。这种完成被认为是初始化错误。
当EA成功初始化之后在策略测试调用ExpertRemove()时,测试通常通过调用OnDeinit()和OnTester()来正常完成。在这种情况下,获取整个交易统计数据和优化准则的值。
示例:
//+------------------------------------------------------------------+
//| Test_ExpertRemove.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
input int ticks_to_close=20;// EA 卸载前的订单号
//+------------------------------------------------------------------+
//| 专家无法初始化函数 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
Print(TimeCurrent(),": " ,__FUNCTION__," reason code = ",reason);
//--- "清除" 注释
Comment("");
//---
}
//+------------------------------------------------------------------+
//| 专家订单号函数 |
//+------------------------------------------------------------------+
void OnTick()
{
static int tick_counter=0;
//---
tick_counter++;
Comment("\nBefore unloading expert advisor ",__FILE__," left",
(ticks_to_close-tick_counter)," ticks");
//--- 以前
if(tick_counter>=ticks_to_close)
{
ExpertRemove();
Print(TimeCurrent(),": ",__FUNCTION__," expert advisor will be unloaded");
}
Print("tick_counter =",tick_counter);
//---
}
//+------------------------------------------------------------------+