//--- defines
#define BALANCE_LOSS_STOP 100.0 // valeur du drawdown du solde à laquelle le test est arrêté
#define EQUITY_LOSS_STOP 100.0 // valeur du drawdown des fonds à laquelle le test est arrêté
//--- paramètres d'entrée
input double InpLots = 0.1; // lots
input uint InpStopLoss = 50; // Stop loss en points
input uint InpTakeProfit = 150; // Take Profit en points
sinput ulong InpMagic = 123; // MagicNumber
sinput ulong InpDeviation = 5; // déviation
//--- variables globales
CTrade trade; // instance de class trade
CSymbolInfo symb; // instance de classe symbol
CAccountInfo account; // instance de la classe compte de trading
...
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
...
//--- initialisation réussie
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//--- met à jour les cotations actuelles
if(!symb.RefreshRates())
return;
...
//--- si le solde ou les capitaux propres ont baissé plus que ce qui est indiqué dans les substitutions de macro BALANCE_LOSS_STOP et EQUITY_LOSS_STOP,
//--- le test est considéré comme un échec et la fonction TesterStop() est appelée
//--- vérifie la perte d'équilibre de plus de 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();
/*
Résultat :
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
*/
}
}
//--- vérifie la perte de capitaux propres de plus de 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();
/*
Résultat :
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
*/
}
}
}
|