TesterStop

テスト中にプログラム操作終了コマンドを発行します。

void  TesterStop();

戻り値

なし

注意事項

TesterStop()関数はテストエージェント(たとえば、特定の数の負け取引または事前に設定されたドローダウンレベルに達した場合)で、EAを定期的に早期にシャットダウンするように設計されています。

TesterStop()の呼び出しはテストの正常終了とみなされるため、 OnTester()関数が呼び出され、累積取引統計および最適化基準の値がストラテジーテスターに送信されます。

ストラテジーテスターでのExpertRemove()の呼び出しもテストの正常終了とみなされて取引統計を取得できますが、EAはエージェントのメモリからアンロードされます。この場合、プログラムを再読み込みするためには、次のパラメータセットのパスを実行する必要があります。よって、TesterStop()はテストの早期終了のための好ましいオプションです。

 

例:

//--- define
#define BALANCE_LOSS_STOP 100.0       // value of the balance drawdown, at which testing is stopped
#define EQUITY_LOSS_STOP   100.0       // value of the equity drawdown, at which testing is stopped
 
//--- 入力パラメータ
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;                 // 取引口座クラスのインスタンス
...
//+------------------------------------------------------------------+
//| エキスパート初期化関数                                                |
//+------------------------------------------------------------------+
int OnInit()
 {
  ...
//--- 正常な初期化
  return(INIT_SUCCEEDED);
 }
//+------------------------------------------------------------------+
//| エキスパートティック関数                                                 |
//+------------------------------------------------------------------+
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 USD, and now has a value of 9899.90 USD. Stop testing.
        TesterStop() called on 9% of 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 USD, and now has a value of 9899.90 USD. Stop testing.
        TesterStop() called on 9% of testing interval
        */
       }
    }
 }

参照

プログラムの実行取り引き戦略のテストExpertRemoveSetReturnError