// El asesor basado en el archivo estándar "MACD Sample.mq5"
// muestra el resultado de la ejecución TesterStatistics() en el manejador del evento Tester
#define MACD_MAGIC 1234502
//---
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
#include <Trade\PositionInfo.mqh>
#include <Trade\AccountInfo.mqh>
//---
input double InpLots =0.1; // Lots
input int InpTakeProfit =50; // Take Profit (in pips)
input int InpTrailingStop =30; // Trailing Stop Level (in pips)
input int InpMACDOpenLevel =3; // MACD open level (in pips)
input int InpMACDCloseLevel=2; // MACD close level (in pips)
input int InpMATrendPeriod =26; // MA trend period
//---
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit(void)
{
//--- creamos todos los objetos necesarios
if(!ExtExpert.Init())
return(INIT_FAILED);
//--- la inicialización ha tenido éxito
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert new tick handling function |
//+------------------------------------------------------------------+
void OnTick(void)
{
static datetime limit_time=0; // última hora de la llamada considerando timeout
//--- si la hora supera el valor establecido limit_time
if(TimeCurrent()>=limit_time)
{
//--- comprobamos los datos
if(Bars(Symbol(),Period())>2*InpMATrendPeriod)
{
//--- en caso de ejecución exitosa, aumentamos limit_time en timeout segundos
if(ExtExpert.Processing())
limit_time=TimeCurrent()+ExtTimeOut;
}
}
}
//+------------------------------------------------------------------+
//| Expert tester handling function |
//+------------------------------------------------------------------+
double OnTester(void)
{
double ret=TesterStatistics(STAT_PROFIT_FACTOR);
double profit=TesterStatistics(STAT_PROFIT);
int trades_total=(int)TesterStatistics(STAT_TRADES);
int profit_total=(int)TesterStatistics(STAT_PROFIT_TRADES);
int loss_total=(int)TesterStatistics(STAT_LOSS_TRADES);
PrintFormat("%s: Profit = %.2f, trades total: %lu, profit trades total: %lu, loss trades total: %lu, profit factor: %.2f",__FUNCTION__,profit,trades_total,profit_total,loss_total,ret);
return(ret);
/*
Resultado:
OnTester: Profit = 209.84, trades total: 13, profit trades total: 11, loss trades total: 2, profit factor: 3.02
final balance 10209.84 USD
OnTester result 3.020606644198363
*/
}
|