// 표준 "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 트렌드 기간
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- 필요한 모든 객체를 생성합니다.
if(!ExtExpert.Init())
return(INIT_FAILED);
//--- 초기화 성공
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert new tick handling function |
//+------------------------------------------------------------------+
void OnTick(void)
{
static datetime limit_time=0; // 'timeout'을 고려한 마지막 호출 시간
//--- if the time exceeds the specified limit_time value
if(TimeCurrent()>=limit_time)
{
//--- 데이터 확인
if(Bars(Symbol(),Period())>2*InpMATrendPeriod)
{
//--- 성공하면 Limit_time을 'timeout'초만큼 늘립니다.
if(ExtExpert.Processing())
limit_time=TimeCurrent()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+
//| Expert tester handling function |
//+------------------------------------------------------------------+
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);
/*
Result:
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
*/
}
|