Download MetaTrader 5
To add comments, please log in or register
Find out how to install MetaTrader on Linux
John May
3688
John May 2013.03.28 14:33 

I get this error when loading metatrader from the command line with a config.ini file

2013.03.27 21:43:46 Exception Encountered an improper argument.

 This error happens if the following functions are contained in the EA:

void OnTesterInit()
void OnTesterPass()
void OnTesterDeinit()

I do not recieve any errors calling the strategy tester from the platform, it only happens when using the configuration file. The documentation is pretty thin on these functions with the exception of one very complex article. Are they only used to transfer frames to a chart in the terminal window? Is there any way to extract the optimized values within  the Ontester function?

Any Ideas? 

Alain Verleyen
Moderator
29544
Alain Verleyen 2013.03.28 15:03  
CappinJack:

I get this error when loading metatrader from the command line with a config.ini file

 This error happens if the following functions are contained in the EA:

I do not recieve any errors calling the strategy tester from the platform, it only happens when using the configuration file. The documentation is pretty thin on these functions with the exception of one very complex article. Are they only used to transfer frames to a chart in the terminal window? Is there any way to extract the optimized values within  the Ontester function?

Any Ideas? 

I think there are not much person who plays with these functions, but if you provide some example code, we can experiment a little to help you. May be it's a good idea to provide us your config file too.
metalriff
42
metalriff 2013.03.28 17:35  
angevoyageur:
I think there are not much person who plays with these functions, but if you provide some example code, we can experiment a little to help you. May be it's a good idea to provide us your config file too.
What does tester authorization error mean? thanks 
Alain Verleyen
Moderator
29544
Alain Verleyen 2013.03.28 17:47  
metalriff:
What does tester authorization error mean? thanks 
Can you be more explicit ? Give us to complete error message, and how you obtain it.
metalriff
42
metalriff 2013.03.28 18:12  
angevoyageur:
Can you be more explicit ? Give us to complete error message, and how you obtain it.
Alain Verleyen
Moderator
29544
Alain Verleyen 2013.03.28 18:37  
metalriff:

Ok, another time don't hijack a topic not related to your problem. Word "tester" is not sufficient to establish a relation ;-)

What version of MT5 are you using ?

metalriff
42
metalriff 2013.03.28 19:10  
angevoyageur:

Ok, another time don't hijack a topic not related to your problem. Word "tester" is not sufficient to establish a relation ;-)

What version of MT5 are you using ?

Sorry for the Jack. 787 
Alain Verleyen
Moderator
29544
Alain Verleyen 2013.03.28 19:12  
metalriff:
Sorry for the Jack. 787 
Ok, unfortunately I don't find any obvious answer to your issue. You have to fill a request to Service Desk. And please, let us know when you have a reply.
John May
3688
John May 2013.03.29 12:34  
angevoyageur:
Ok, unfortunately I don't find any obvious answer to your issue. You have to fill a request to Service Desk. And please, let us know when you have a reply.

I have put in the request.

John May
3688
John May 2013.03.29 14:11  
angevoyageur:
I think there are not much person who plays with these functions, but if you provide some example code, we can experiment a little to help you. May be it's a good idea to provide us your config file too.

I have attached a couple of files to this message so you can replicate this error.  This is the confuration file:

 

[Common]
Login=1401989
ProxyEnable=0
ProxyType=0
ProxyAddress=
ProxyLogin=10
ProxyPassword=10
KeepPrivate=1
NewsEnable=1
CertInstall=1
 
[Charts]
ProfileLast=Euro
MaxBars=50000
PrintColor=0
SaveDeleted=1
 
[Experts]
AllowLiveTrading=0
AllowDllImport=0
Enabled=1
Account=0
Profile=0
 
[Objects]
ShowPropertiesOnCreate=0
SelectOneClick=0
MagnetSens=10
 
;+------------------------------------------------------------------------------
;| Start testing or optimization of the specified Expert Advisor                |
;+------------------------------------------------------------------------------
[Tester]
;--- The EA is located in terminal_data_directory\MQL5\Experts\Examples\Moving Average
Expert=Examples\Moving Average\Moving Average
;--- The symbol for testing/optimization
Symbol=EURUSD
;--- The timeframe for testing/optimization
Period=H1
;--- Initial deposit
Deposit=100000
;--- Leverage for testing
Leverage=1:100
;--- The "1 minute OHLC" mode
Model=1
;--- Execution of trade orders with a random delay
ExecutionMode=0
;--- Genetic optimization This is what triggers the error if it is set to anthing but 0
Optimization=2
;--- Optimization criterion - Maximum balance drawdown value
OptimizationCriterion=0
;--- Start and end dates of the testing range
FromDate=2013.03.20
ToDate=2013.03.23
;--- Custom mode of forward testing
ForwardMode=0
;--- Start date of forward testing
ForwardDate=2011.03.01
;--- A file with a report will be saved in terminal_installation_folder
Report=opti-eurusd
;--- If the specified report already exists, it will be overwritten
ReplaceReport=1
;--- Set automatic terminal shutdown upon completion of testing/optimization
ShutdownTerminal=0

 The Moving Average EA is what is intsalled in the \Experts\Examples\Moving Average directory:

//+------------------------------------------------------------------+
//|                                              Moving Averages.mq5 |
//|                   Copyright 2009-2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2009-2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

#include <Trade\Trade.mqh>

input double MaximumRisk        = 0.02;    // Maximum Risk in percentage
input double DecreaseFactor     = 3;       // Descrease factor
input int    MovingPeriod       = 12;      // Moving Average period
input int    MovingShift        = 6;       // Moving Average shift
//---
int   ExtHandle=0;
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double TradeSizeOptimized(void)
  {
   double price=0.0;
   double margin=0.0;
//--- select lot size
   if(!SymbolInfoDouble(_Symbol,SYMBOL_ASK,price))               return(0.0);
   if(!OrderCalcMargin(ORDER_TYPE_BUY,_Symbol,1.0,price,margin)) return(0.0);
   if(margin<=0.0)                                               return(0.0);

   double lot=NormalizeDouble(AccountInfoDouble(ACCOUNT_FREEMARGIN)*MaximumRisk/margin,2);
//--- calculate number of losses orders without a break
   if(DecreaseFactor>0)
     {
      //--- select history for access
      HistorySelect(0,TimeCurrent());
      //---
      int    orders=HistoryDealsTotal();  // total history deals
      int    losses=0;                    // number of losses orders without a break

      for(int i=orders-1;i>=0;i--)
        {
         ulong ticket=HistoryDealGetTicket(i);
         if(ticket==0)
           {
            Print("HistoryDealGetTicket failed, no trade history");
            break;
           }
         //--- check symbol
         if(HistoryDealGetString(ticket,DEAL_SYMBOL)!=_Symbol) continue;
         //--- check profit
         double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT);
         if(profit>0.0) break;
         if(profit<0.0) losses++;
        }
      //---
      if(losses>1) lot=NormalizeDouble(lot-lot*losses/DecreaseFactor,1);
     }
//--- normalize and check limits
   double stepvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   lot=stepvol*NormalizeDouble(lot/stepvol,0);

   double minvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   if(lot<minvol) lot=minvol;

   double maxvol=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   if(lot>maxvol) lot=maxvol;
//--- return trading volume
   return(lot);
  }
//+------------------------------------------------------------------+
//| Check for open position conditions                               |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   MqlRates rt[2];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1) return;
//--- get current Moving Average 
   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1)
     {
      Print("CopyBuffer from iMA failed, no data");
      return;
     }
//--- check signals
   ENUM_ORDER_TYPE signal=WRONG_VALUE;

   if(rt[0].open>ma[0] && rt[0].close<ma[0]) signal=ORDER_TYPE_SELL;    // sell conditions
   else
      if(rt[0].open<ma[0] && rt[0].close>ma[0]) signal=ORDER_TYPE_BUY;  // buy conditions
//--- additional checking
   if(signal!=WRONG_VALUE)
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
         if(Bars(_Symbol,_Period)>100)
           {
            CTrade trade;
            trade.PositionOpen(_Symbol,signal,TradeSizeOptimized(),
                               SymbolInfoDouble(_Symbol,signal==ORDER_TYPE_SELL ? SYMBOL_BID:SYMBOL_ASK),
                               0,0);
           }
//---
  }
//+------------------------------------------------------------------+
//| Check for close position conditions                              |
//+------------------------------------------------------------------+
void CheckForClose()
  {
   MqlRates rt[2];
//--- go trading only for first ticks of new bar
   if(CopyRates(_Symbol,_Period,0,2,rt)!=2)
     {
      Print("CopyRates of ",_Symbol," failed, no history");
      return;
     }
   if(rt[1].tick_volume>1) return;
//--- get current Moving Average 
   double   ma[1];
   if(CopyBuffer(ExtHandle,0,0,1,ma)!=1)
     {
      Print("CopyBuffer from iMA failed, no data");
      return;
     }
//--- positions already selected before
   bool signal=false;
   long type=PositionGetInteger(POSITION_TYPE);

   if(type==(long)POSITION_TYPE_BUY   && rt[0].open>ma[0] && rt[0].close<ma[0]) signal=true;
   if(type==(long)POSITION_TYPE_SELL  && rt[0].open<ma[0] && rt[0].close>ma[0]) signal=true;
//--- additional checking
   if(signal)
      if(TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
         if(Bars(_Symbol,_Period)>100)
           {
            CTrade trade;
            trade.PositionClose(_Symbol,3);
           }
//---
  }
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ExtHandle=iMA(_Symbol,_Period,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE);
   if(ExtHandle==INVALID_HANDLE)
     {
      printf("Error creating MA indicator");
      return(-1);
     }
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(PositionSelect(_Symbol)) CheckForClose();
   else                        CheckForOpen();
//---
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
 void OnTesterInit()
 {
 }
void OnTesterPass()
 {
 }
void OnTesterDeinit()
 {
 }

 I have just added the OnTester functions at the end. Now maybe that is my problem, that I do not have any code within the functions. But here are the errors when using the ini file:

2013.03.29 09:09:00     Network '1401989': terminal synchronized with MetaQuotes Software Corp.
2013.03.29 09:08:59     Network '1401989': previous successful authorization performed from 24.180.64.171 on 2013.03.29 14:03:12
2013.03.29 09:08:59     Network '1401989': authorized on MetaQuotes-Demo through Access Point USA
2013.03.29 09:08:59     Exception       Encountered an improper argument.
2013.03.29 09:08:58     Terminal        openCL is not supported
2013.03.29 09:08:58     Terminal        launched with C:\Program Files\Meta5_OPTIM\MQL5\MAconfigauto.ini
2013.03.29 09:08:58     Terminal        MetaTrader 5 build 787 started (MetaQuotes Software Corp.)

 

I am using Windows XP Pro Service Pack 3

Here is my command line aurgument

"C:\Program Files\Meta5_OPTIM\terminal.exe" /config:C:\Program Files\Meta5_OPTIM\MQL5\MAconfigauto.ini
Files:
Simon Gniadkowski
Moderator
17975
Simon Gniadkowski 2013.03.31 13:17  
CappinJack:

I have attached a couple of files to this message so you can replicate this error.  This is the confuration file:

 

 The Moving Average EA is what is intsalled in the \Experts\Examples\Moving Average directory:

 I have just added the OnTester functions at the end. Now maybe that is my problem, that I do not have any code within the functions. But here are the errors when using the ini file:

 

I am using Windows XP Pro Service Pack 3

Here is my command line aurgument

I got this working with a few modifications . . .  some points follow:

I don't think this will work,  you have a space . . .

"C:\Program Files\Meta5_OPTIM\terminal.exe" /config:C:\Program Files\Meta5_OPTIM\MQL5\MAconfigauto.ini

change it to this

"C:\Program Files\Meta5_OPTIM\terminal.exe" /config:"C:\Program Files\Meta5_OPTIM\MQL5\MAconfigauto.ini"

 I added an entry in the configuration file for the set file

ExpertParameters=MA_TEST.set

 ExpertParameters — name of a file containing input parameters of an Expert Advisor. This file must be in the \tester folder of the terminal installation directory.

 I made some other changes,  but I don't think they will make a difference . . . try these changes one by one,  see if they help and let us know.

/ /123
To add comments, please log in or register