TesterStop

测试时,给予程序操作完成命令。

void  TesterStop();

返回值

无返回值。

注意

TesterStop()函数是为测试代理上的EA例行早期关闭而设计的 – 例如,当达到指定数量的亏损交易或预先设定的下降水平时。

TesterStop()调用被认为是测试的正常完成,因此OnTester() 函数被调用,将全部累积的交易统计数据和优化准则值提交到策略测试。

在策略测试中调用 ExpertRemove()还意味着正常测试完成并允许获取交易统计数据,但EA从代理内存中卸载。在这种情况下,对下一组参数执行传递需要一段时间来重新加载重新。因此,TesterStop() 是早期例行完成测试的首选选项。

 

示例:

//--- 定义
#define BALANCE_LOSS_STOP  100.0       // 结余回撤值,在该值停止测试
#define EQUITY_LOSS_STOP   100.0       // 净值回撤值,在该值停止测试
 
//--- 输入参数
input  double  InpLots        =  0.1;  // 手数
input  uint    InpStopLoss    =  50;   // 止损点数
input  uint    InpTakeProfit  =  150;  // 止盈点数
sinput ulong   InpMagic       =  123;  // 幻数
sinput ulong   InpDeviation   =  5;    // 偏差
//--- 全局变量
CTrade      trade;                     // 交易类实例
CSymbolInfo symb;                      // 交易品种类实例
CAccountInfo account;                  // 交易账户类实例
...
//+------------------------------------------------------------------+
//| EA交易初始化函数                                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   ...
//--- 成功初始化
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- 更新当前报价
   if(!symb.RefreshRates())
      return;
   ...
 
//--- 如果余额或净值下降幅度超过BALANCE_LOSS_STOP和EQUITY_LOSS_STOP宏替换中指定的值,
//--- 则测试被认为不成功,并且调用TesterStop()函数
//--- 检查结余损失是否超过BALANCE_LOSS_STOP
   if(balance_prev!=account.Balance())
     {
      if(account.Balance()<balance_prev-BALANCE_LOSS_STOP)
        {
         PrintFormat("The initial balance of %.2f %s decreased by %.2f %s, and now has a value of %.2f %s. Stop testing.",balance_prev,account.Currency(),balance_prev-account.Balance(),account.Currency(),account.Balance(),account.Currency());
         TesterStop();
         /*
        结果:
         The initial balance of 10000.00 USD decreased by 100.10 USDand now has a value of 9899.90 USDStop testing.
         TesterStop() called on 9of testing interval
         */
        }
     }
//--- 检查净值损失是否超过EQUITY_LOSS_STOP
   if(equity_prev!=account.Equity())
     {
      if(account.Equity()<equity_prev-EQUITY_LOSS_STOP)
        {
         PrintFormat("The initial equity of %.2f %s decreased by %.2f %s, and now has a value of %.2f %s. Stop testing.",equity_prev,account.Currency(),equity_prev-account.Equity(),account.Currency(),account.Equity(),account.Currency());
         TesterStop();
         /*
        结果:
         The initial equity of 10000.00 USD decreased by 100.10 USDand now has a value of 9899.90 USDStop testing.
         TesterStop() called on 9of testing interval
         */
        }
     }
  }

另见

程序运行测试交易策略ExpertRemoveSetReturnError