//--- defines
#define BALANCE_LOSS_STOP 100.0 // valor do rebaixamento do saldo durante o qual o teste será interrompido
#define EQUITY_LOSS_STOP 100.0 // valor do rebaixamento dos fundos durante o qual o teste será interrompido
//--- input parameters
input double InpLots = 0.1; // lotes
input uint InpStopLoss = 50; // Stop loss em pontos
input uint InpTakeProfit = 150; // Take Profit em pontos
sinput ulong InpMagic = 123; // MagicNumber
sinput ulong InpDeviation = 5; // desvio
//--- global variables
CTrade trade; // instância da classe de negociação
CSymbolInfo symb; // instância da classe de símbolo
CAccountInfo account; // instância da classe de conta de negociação
...
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
...
//--- Inicialização bem-sucedida
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- atualizamos as cotações atuais
if(!symb.RefreshRates())
return;
...
//--- se o saldo ou os fundos caírem mais do que o indicado nas macrosubstituições BALANCE_LOSS_STOP e EQUITY_LOSS_STOP,
//--- consideramos o teste falho e chamamos a função TesterStop()
//--- verificamos a perda do saldo mais do que em 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();
/*
Resultado:
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
*/
}
}
//--- verificamos a perda dos fundos mais do que em 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();
/*
Resultado:
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
*/
}
}
}
|