// Советник на основе стандартного файла "MACD Sample.mq5" // показывает результат выполнения TesterStatistics() в обработчике события 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) { //--- создадим все необходимые объекты if(!ExtExpert.Init()) return(INIT_FAILED); //--- успешная инициализация return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert new tick handling function | //+------------------------------------------------------------------+ void OnTick(void) { static datetime limit_time=0; // последнее время вызова с учетом timeout //--- если время превысило установленное значение limit_time if(TimeCurrent()>=limit_time) { //--- проверим данные if(Bars(Symbol(),Period())>2*InpMATrendPeriod) { //--- в случае успешного выполнения увеличим limit_time на timeout секунд 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); /* Результат: 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 */ } |