//--- 정의
#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; // 거래 계정 클래스 인스턴스
...
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
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();
/*
Result:
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();
/*
Result:
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
*/
}
}
}
|