// 標準の「MACD Sample.mq5」ファイルに基づく EA
// TesterイベントハンドラのTesterStatistics()の結果を表示する
#define MACD_MAGIC 1234502
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
input double InpLots =0.1; // ロット
input int InpTakeProfit =50; // 単位のテイクプロフィット(ピップス単位)
input int InpTrailingStop =30; // トレーリングストップレベル(ピップス単位)
input int InpMACDOpenLevel =3; // MACDオープンレベル(ピップス単位)
input int InpMACDCloseLevel=2; // MACDクローズレベル(ピップス単位)
input int InpMATrendPeriod =26; // MAトレンド期間
//+------------------------------------------------------------------+
//| エキスパート初期化関数 |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- 必要なオブジェクトをすべて作成する
if(!ExtExpert.Init())
return(INIT_FAILED);
//--- 正常な初期化
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| エキスパートティック処理関数 |
//+------------------------------------------------------------------+
void OnTick(void)
{
static datetime limit_time=0; // last call time considering 'timeout'
//--- 時間が指定されたlimit_time値を超えた場合
if(TimeCurrent()>=limit_time)
{
//--- データを確認する
if(Bars(Symbol(),Period())>2*InpMATrendPeriod)
{
//--- 成功した場合は、limit_timeを「timeout」秒だけ増やす
if(ExtExpert.Processing())
limit_time=TimeCurrent()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+
//| エキスパートテスター処理関数 |
//+------------------------------------------------------------------+
double OnTester(void)
{
double ret=TesterStatistics(STAT_PROFIT_FACTOR);
double profit=TesterStatistics(STAT_PROFIT);
int trades_total=(int)TesterStatistics(STAT_TRADES);
int profit_total=(int)TesterStatistics(STAT_PROFIT_TRADES);
int loss_total=(int)TesterStatistics(STAT_LOSS_TRADES);
PrintFormat("%s: Profit = %.2f, trades total: %lu, profit trades total: %lu, loss trades total: %lu, profit factor: %.2f",__FUNCTION__,profit,trades_total,profit_total,loss_total,ret);
return(ret);
/*
結果:
OnTester: Profit = 209.84, trades total: 13, profit trades total: 11, loss trades total: 2, profit factor: 3.02
final balance 10209.84 USD
OnTester result 3.020606644198363
*/
}
|