//--- 정의
#define BALANCE_LOSS_DEPOSIT 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; // 거래 계정 클래스 인스턴스
...
double balance_dep_summ; // 잔액 충전 총액
uint balance_dep_total; // 잔액 충전 횟수
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
...
//--- 초기 잔액 값을 저장합니다.
balance_prev=account.Balance();
balance_dep_summ=0;
balance_dep_total=0;
//--- 초기화 성공
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- 현재 호가 업데이트
if(!symb.RefreshRates())
return;
...
//--- 잔액이 BALANCE_LOSS_DEPOSIT 매크로 대체에 설정된 것보다 더 많이 떨어진 경우,
//--- 계정을 충전하고 TesterDeposit() 함수를 호출해야 합니다.
//--- BALANCE_LOSS_DEPOSIT 이상의 잔액 손실을 확인
if(balance_prev!=account.Balance())
{
if(account.Balance()<balance_prev-BALANCE_LOSS_DEPOSIT)
{
double loss=balance_prev-account.Balance();
PrintFormat("The initial balance of %.2f %s decreased by %.2f %s. It is necessary to make a deposit to the account for %.2f %s.",balance_prev,account.Currency(),loss,account.Currency(),loss,account.Currency());
if(TesterDeposit(loss))
{
balance_dep_total++;
balance_dep_summ+=loss;
balance_prev=account.Balance();
PrintFormat("Funds have been deposited into the account. Account balance: %.2f %s.",account.Balance(),account.Currency());
PrintFormat("Total deposits: %lu. Amount of deposits: %.2f %s.",balance_dep_total,balance_dep_summ,account.Currency());
}
/*
Result:
The initial balance of 10000.00 USD decreased by 116.00 USD. It is necessary to make a deposit to the account for 116.00 USD.
deal #45 balance 116.00 [deposit] done
Funds have been deposited into the account. Account balance: 10000.00 USD.
Total deposits: 1. Amount of deposits: 116.00 USD.
*/
}
}
}
//+------------------------------------------------------------------+
//| Tester function |
//+------------------------------------------------------------------+
double OnTester()
{
//--- 재무적 측면에서 최대 잔액 감소를 출력 핸들러 값으로 설정합니다.
double ret=TesterStatistics(STAT_BALANCE_DD);
//--- 인출, 예금 수 및 총 금액에 대한 메시지를 로그에 표시합니다.
PrintFormat("%s: Maximum balance drawdown in money: %.2f %s. Total deposits: %lu. Amount of deposits: %.2f %s.",__FUNCTION__,ret,account.Currency(),balance_dep_total,balance_dep_summ,account.Currency());
//--- 결과 반환
return(ret);
/*
Result:
OnTester: Maximum balance drawdown in money: 5188.50 USD. Total deposits: 46. Amount of deposits: 5128.50 USD.
final balance 4867.50 USD
OnTester result 5188.5
*/
}
|