//--- 정의
#define BALANCE_PROFIT_WITHDRAWAL 5 // 테스터의 계좌에서 자금이 인출될 때 잔액 수익의 가치
//--- 입력 매개변수
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_op_sum; // 잔액 작업의 총량
uint balance_op_total; // 잔액 작업의 횟수
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
...
//--- 초기 잔액 값을 저장합니다.
balance_prev=account.Balance();
balance_op_sum=0;
balance_op_total=0;
//--- 초기화 성공
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- 현재 호가 업데이트
if(!symb.RefreshRates())
return;
...
//--- 잔액 수익이 BALANCE_PROFIT_WITHDRAWAL 매크로 대체에 지정된 값만큼 현재 잔액을 초과하는 경우,
//--- 이 자금을 계좌에서 인출해야 합니다. Call the TesterWithdrawal() function.
//--- BALANCE_PROFIT_WITHDRAWAL 초과에 대한 잔액 수익 확인
if(balance_prev!=account.Balance())
{
if(account.Balance()>balance_prev+BALANCE_PROFIT_WITHDRAWAL)
{
double profit=account.Balance()-balance_prev;
PrintFormat("The account balance has been increased by %.2f %s. Need to withdraw these funds from the account.",profit,account.Currency());
if(TesterWithdrawal(profit))
{
balance_op_total++;
balance_op_summ+=profit;
balance_prev=account.Balance();
PrintFormat("Funds have been withdrawn from the account. Account balance: %.2f %s.",account.Balance(),account.Currency());
PrintFormat("Total withdrawals: %lu. Amount of withdrawals: %.2f %s.",balance_op_total,balance_op_summ,account.Currency());
}
/*
Result:
The account balance has been increased by 21.00 USD. Need to withdraw these funds from the account.
deal #13 balance -21.00 [withdrawal] done
Funds have been withdrawn from the account. Account balance: 10000.00 USD.
Total withdrawals: 1. Amount of withdrawals: 21.00 USD.
*/
}
}
}
//+------------------------------------------------------------------+
//| Tester function |
//+------------------------------------------------------------------+
double OnTester()
{
//--- 재무적 측면에서 최대 잔액 감소를 출력 핸들러 값으로 설정합니다.
double ret=TesterStatistics(STAT_BALANCE_DD);
//--- 인출 횟수, 총 인출 금액 및 손실 대한 메시지를 로그에 표시합니다.
PrintFormat("%s: Maximum balance drawdown in money: %.2f %s. Total withdrawals: %lu. Amount of withdrawals: %.2f %s.",__FUNCTION__,ret,account.Currency(),balance_op_total,balance_op_summ,account.Currency());
//--- 결과 반환
return(ret);
/*
Result:
OnTester: Maximum balance drawdown in money: 5188.50 USD. Total withdrawals: 2. Amount of withdrawals: 36.00 USD.
final balance 4867.50 USD
OnTester result 5188.5
*/
}
|