//--- defines
#define BALANCE_LOSS_STOP 100.0 // значение просадки баланса, при котором будет остановлено тестирование
#define EQUITY_LOSS_STOP 100.0 // значение просадки средств, при котором будет остановлено тестирование
//--- input parameters
input double InpLots = 0.1; // лоты
input uint InpStopLoss = 50; // Stop loss в пунктах
input uint InpTakeProfit = 150; // Take Profit в пунктах
sinput ulong InpMagic = 123; // MagicNumber
sinput ulong InpDeviation = 5; // отклонение
//--- global variables
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();
/*
Результат:
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();
/*
Результат:
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
*/
}
}
}
|