//--- define
#define BALANCE_PROFIT_WITHDRAWAL 5 // the value of the balance profit, at which funds are withdrawn from the account in the tester
//-- parametri di input
input double InpLots = 0.1; // Lotti
input uint InpStopLoss = 50; // Stop loss in punti
input uint InpTakeProfit = 150; // Take Profit in punti
sinput ulong InpMagic = 123; // Numero Magico
sinput ulong InpDeviation = 5; // Deviazione
//---variabili globali
CTrade trade; // istanza della classe di trading
CSymbolInfo symb; // istanza della classe del simbolo
CAccountInfo account; // istanza di classe del conto di trading
...
double balance_op_sum; // total amount of balance operations
uint balance_op_total; // number of balance operations
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
...
//-- salvare i valori del saldo iniziale
balance_prev=account.Balance();
balance_op_sum=0;
balance_op_total=0;
//-- inizializzazione avvenuta con successo
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//-- aggiornare le quotazioni attuali
if(!symb.RefreshRates())
return;
...
//-- se il profitto del saldo supera il saldo corrente del valore specificato nella macro sostituzione BALANCE_PROFIT_WITHDRAWAL,
//-- è necessario prelevare questi fondi dal conto. Chiamare la funzione TesterWithdrawal().
//-- controllare il profitto del saldo per il superamento di 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());
}
/*
Risultato:
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()
{
//--- impostare il drawdown massimo del saldo in termini monetari come valore del gestore dell'output
double ret=TesterStatistics(STAT_BALANCE_DD);
//-- visualizzare un messaggio sul drawdown, il numero di prelievi e il loro importo totale nel registro
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());
//-- restituire il risultato
return(ret);
/*
Risultato:
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
*/
}
|