Learning and writing together in MQL5 - page 13

 
Yedelkin:

Strange. You need code for MQL5, which should already be on the website. All you have to do is look it up. That's exactly what I'm talking about.

But that's up to you.

It's a very tedious search, maybe someone will just tell you.

By the way, I have remade this code for mql5. Maybe someone could use it.

input double risk=0.01;
   double lot_min =SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MIN);
   double lot_max =SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_MAX);
   double lot_step=SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
   double contract=SymbolInfoDouble(_Symbol,SYMBOL_TRADE_CONTRACT_SIZE);
   double free_margin=AccountInfoDouble(ACCOUNT_FREEMARGIN);
   int leverage=(int)AccountInfoInteger(ACCOUNT_LEVERAGE);
   double lot;
   
     lot=NormalizeDouble(free_margin*risk*leverage/contract,2);
     lot=NormalizeDouble(lot/lot_step,0)*lot_step;
   if(lot<lot_min) lot=lot_min;
   if(lot>lot_max) lot=lot_max;
 
Gentlemen.
please comment:

ENUM_TRADE_RETURN_CODES
Code ID Description
10004 TRADE_RETCODE_REQUOTE Request rejected
10006 TRADE_RETCODE_REJECT Request rejected
...
no code 10005. Is this not an error?
Respectfully ...
 

Question. There is a function called GetTickCount () - itreturns the number of milliseconds elapsed since the system started. The note says that "the count is limited by the resolution of the system timer. Since the time is stored as an unsigned integer, it overflows every 49.7 days when the computer is running continuously".

And what happens after the counter overflows? Does it reset and start a new countdown, or does the system freeze?

 

Yedelkin:

What happens when the counter overflows? Does it reset and start a new count, or does the system freeze?

It overflows and starts from zero.
 
Renat:
It overflows and starts from scratch.
OK, got it!
 

Question. The description of switch(expression){...} says that "the switch operator's expression must be of integer type". I've seen the description of this operator with expressions of other types on the Internet. Will the use of switch operator be extended by adding expressions of string type?

 
Yedelkin:

Question. The description of switch(expression){...} says that "the switch operator's expression must be of integer type". I've seen the description of this operator with expressions of other types on the Internet. Will we extend use of the switch operator by adding expressions of the string type?

No, unfortunately, it won't. For string types only if ... else if ... else .

Using integer types in switch will speed up the switch operator several times as much as if

Документация по MQL5: Основы языка / Типы данных / Целые типы
Документация по MQL5: Основы языка / Типы данных / Целые типы
  • www.mql5.com
Основы языка / Типы данных / Целые типы - Документация по MQL5
 
stringo:

No, unfortunately it won't. For string types only if ... else if ... else

Using integer types in switch will speed up the code several times as much as if

OK, thanks for the tip!
 

Question. The StringConcatenate() function description says that "StringConcatenate() works faster and more economical in memory than string linking by means of addition operations due to the fact that temporary variables of string type are not used". I used the examples from the Reference Manual, changing them slightly:

   string a="a",b="b",c;
   uint   start,stop;
   long   i,length=10000000;
//--- первый способ
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      c=a+b;
     }
   stop=GetTickCount();
   Print("time for 'c = a + b' = ",(stop-start)," milliseconds, i = ",i);


//--- второй способ
   a="a"; // заново инициализируем переменную a
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      StringAdd(a,b);
     }
   stop=GetTickCount();
   Print("time for 'StringAdd(a,b)' = ",(stop-start)," milliseconds, i = ",i);

//--- третий способ
   a="a";c="";  
   start=GetTickCount();
   for(i=0;i<length;i++)
     {
      int k=StringConcatenate(c,a,b);
      //c="";   //с такой строчкой работает ещё дольше.          
     }
   stop=GetTickCount();
   Print("time for 'StringConcatenate(c,a,b)' = ",(stop-start)," milliseconds, i = ",i);
The output is:

DR 0 DoubleToString (EURGBP,M1) 22:15:55  time for 'c = a + b'              = 2359 milliseconds, i = 10000000
QE 0 DoubleToString (EURGBP,M1) 22:15:56  time for 'StringAdd(a,b)'          = 1031 milliseconds, i = 10000000
FE 0 DoubleToString (EURGBP,M1) 22:16:00  time for 'StringConcatenate(c,a,b)' = 3891 milliseconds, i = 10000000

It turns out that StringConcatenate works slower than string binding using addition operations. What is the problem?

Документация по MQL5: Основы языка / Типы данных / Тип string
Документация по MQL5: Основы языка / Типы данных / Тип string
  • www.mql5.com
Основы языка / Типы данных / Тип string - Документация по MQL5
 
Yedelkin:

Question. The StringConcatenate() function description says that "StringConcatenate() works faster and more economical in memory than string linking by means of addition operations due to the fact that temporary variables of string type are not used". I used examples from the Reference, changing them a bit:

I got the output:

It turns out that StringConcatenate works slower than string binding using addition operations. What's the snag?

It's a bit of a misnomer to check (if I understand it correctly). The trick of the function is something else...

Approximately this code

////////////////////////////////////////////////////////////////////////////////
//             Global variables, used in working the trade system             //
////////////////////////////////////////////////////////////////////////////////
string a="Пример";
double b=1.26,c = 1.27;
string d;

uint   start,stop;

long   i,length=10000000;
////////////////////////////////////////////////////////////////////////////////
void OnStart()
{
//----------------------------------------------------------------------------//
//Work variables
//----------------------------------------------------------------------------//

start=GetTickCount();
   
  for(i=0;i<length;i++)
  {
  d=a+(string)b+(string)c;
  }

stop=GetTickCount();

Print("time for 'd = a + b + c' = ",(stop-start)," milliseconds, i = ",i);

//Второй способ
d= "";

start=GetTickCount();

  for(i=0;i<length;i++)
  {
  StringAdd(d,a);
  StringAdd(d,(string)b);
  StringAdd(d,(string)c);
  }
stop=GetTickCount();

Print("time for 'StringAdd()' = ",(stop-start)," milliseconds, i = ",i);

//Третий способ
d= "";

start=GetTickCount();

  for(i=0;i<length;i++)
  {
  int k=StringConcatenate(d,a,b,c);
  }

stop=GetTickCount();

Print("time for 'StringConcatenate(d,a,b,c)' = ",(stop-start)," milliseconds, i = ",i);
//----------------------------------------------------------------------------//   
}
////////////////////////////////////////////////////////////////////////////////

And this result

2011.04.15 15:28:58     123 (EURUSD,D1) time for 'd = a + b + c' = 81094 milliseconds, i = 10000000
2011.04.15 15:30:24     123 (EURUSD,D1) time for 'StringAdd()' = 85828 milliseconds, i = 10000000
2011.04.15 15:31:46     123 (EURUSD,D1) time for 'StringConcatenate(d,a,b,c)' = 81812 milliseconds, i = 10000000
2011.04.15 15:33:36     123 (EURUSD,D1) time for 'd = a + b + c' = 82938 milliseconds, i = 10000000
2011.04.15 15:35:00     123 (EURUSD,D1) time for 'StringAdd()' = 83859 milliseconds, i = 10000000
2011.04.15 15:36:21     123 (EURUSD,D1) time for 'StringConcatenate(d,a,b,c)' = 80719 milliseconds, i = 10000000

PS

Most likely, the line d= "" should have been placed in the for loop, but I don't think this bug has much effect on the result.