Errors, bugs, questions - page 100

 
Urain:

Is there a forced termination of the OnTester() function

or why the history of transactions before the custom function exists and returns zero afterwards :

double OnTester()
  {
   int HTD=-1;
   Custom_func();
   if(HistorySelect(0,TimeCurrent()))HTD=HistoryDealsTotal();   
   return(HTD);
  }

what functions are not working in the tester ?

how can the tester (during optimisation) signal to the outside that something is wrong (print alerts, nothing works) ?

Apparently everyone is asleep tonight.
 
Urain:
Apparently, everyone is asleep today.

Have you looked at the agent logs, maybe everything is there?

As far as I know, printers are not displayed in the main tester log only during optimization (in normal mode everything is OK).

OnTester() as I understand it is not possible to forcibly exit. And what for? It simply calculates a certain test result (moreover, it is essentially used only for optimization)?

OnTester:
The OnTester() function is a Tester event handler that is automatically generated at the end of the Expert Advisor's historical testing on a given date interval. The function must be defined with type double, it has no parameters:

doubleOnTester();

The function is called immediately before OnDeinit() and has the return type double. The OnTester() function can be used only in experts during testing. Its main purpose is to calculate some value to be used as the Custom max criterion in the genetic optimization of input parameters.


PS

> why does the history of transactions before a custom function, but after that it shows zero...

Perhaps this is a question for the developers.

As far as I understand, OnTester must return the number of trades (if there are any), while Custom_func() is understood as a custom function?

 
Urain:

Dedicated to the developers ...

You guys at least would have warned if you give an opportunity that before in principle was not possible.

I wasted twenty-four hours trying to catch this bug.

Don't tell me that it's okay, of course I know that, but I've wasted 24 hours just because I'm used to the fact that with this

I'm used to getting the compiler to give me an error.

What's the right way to do it? Is it "==" or is it "="?
 
Urain:

Is there a forced termination of the OnTester() function

or why the history of transactions before the custom function exists and returns zero afterwards :

what functions are not working in the tester ?

how to signal from tester (during optimisation) to the outside that something is wrong (prints alerts nothing works) ?

Thank you for your message. Your application has been received - we are dealing with it.

 

How do I calculate the maximum allowable lot by margin to open a new position? In MQL4 it was done as follows:

MaxLot=AccountFreeMargin()/MarketInfo(Symbol(),MODE_MARGINREQUIRED);
 
EvgeTrofi:

How do I calculate the maximum allowable lot by margin to open a new position? In MQL4 it was done like this:

Approximately like this:

double CalculateMaxVolume(string symbol)
  {
   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)/margin,2);
//--- 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);
  }
This code not only calculates the maximum volume, but also fits it exactly within the limits of the symbol settings.
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
Документация по MQL5: Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте
  • www.mql5.com
Стандартные константы, перечисления и структуры / Состояние окружения / Информация об инструменте - Документация по MQL5
 
Renat:

It goes something like this:

This code not only calculates the maximum volume, but also fits it exactly within the limits of the character setting.
Thank you! I don't have OrderCalcMargin() in my help :)
 
EvgeTrofi:
Thank you! I don't have OrderCalcMargin() in my help :)
This function has been added a long time ago - look in the documentation, please.
 
EvgeTrofi:
So what's the right way in the end? Is it "==" or is it "="?

Either way.

if(a==0){expression} means if a is 0 then it's true, so we execute {expression}.

if(a=0){expression} equals if(a){a=0;expression} if a is true, {a=0;expression}.

 
Interesting:

Have you looked at the agent logs, maybe everything is there?

As far as I know, printers are not displayed in the main tester log only during optimization (in normal mode everything is OK).

OnTester() as I understand it is not possible to forcibly exit. And what for, it just calculates a certain test result (which in fact is used only for optimization)?

PS

> Why does the history of transactions before a custom function exist and give out zero afterwards...

Perhaps this is a problem for the developers.

As far as I understand, the OnTester should return the number of deals (if there are any), while the custom function is Custom_func()?

That's the problem is that in the optimization itself the program does not work like in other situations (that's why I need to send message from under OnTester).

For this purpose I have created analog of print (function that creates a file for the sake of printing a string passed to the function as a parameter).

int prints=0;// счётчик вызовов, должен быть обьявлен глобально
//+------------------------------------------------------------------+
//| вывод информации из под тестера                                  |
//+------------------------------------------------------------------+
void WriteFilePrint(string text,string folder="Print")
  {
   string subfolder="Print";
   int han=FileOpen(subfolder+"\\"+folder+(string)prints+".csv",FILE_WRITE|FILE_CSV,";");
   if(han!=INVALID_HANDLE)
     {
      FileWrite(han,text);
      FileClose(han);
     }
   else Print("File open failed"+subfolder+"\\"+folder+".txt, error",GetLastError());
   prints++;
  }

Thus, I managed to catch the incorrect execution of some functions in OnTester.

Reason: