Discussion on MQL4 documentation - page 18

 
Well... The way I see it, that's the right answer:

void SendMail( string subject, string some_text)
Sends an email to the address specified in the settings window on the Mail tab.
The function does not work in test mode. This function also cannot be called from the user indicators.
Sending may be prohibited in the settings, also the e-mail address may not be specified. The GetLastError() function must be called to get the error information.
[...]

In the indicator, admittedly, I haven't checked... :)

Z.U. I object to the title of the topic and propose to rename it to something like this: "Improvement of MQL4 documentation: removal of inaccuracies and deficiencies". Something like that.
 
In the example for the OrderSelect() function, I came across such an expression:
if(OrderSelect(12470, SELECT_BY_TICKET)==true) ...
Then I saw it in other places in the documentation as well.

Please explain, is it just a programming style?
If it's not, what is the reason for using the comparison operation for logical variables?
Why isn't a simpler expression used?
if(OrderSelect(12470, SELECT_BY_TICKET)) ...
 
Yurixx:
Why isn't a simpler expression used:

The first expression is intuitively more understandable and not controversial especially for beginners, although the second expression is used more widely probably.
 
what is a formal parameter and what does it have to do with parameters passed by reference?
 
Often functions for the calculation of values require some parameters as input. For example, if we look at OrderSend() function, it has a lot of such parameters:
  • Symbol
  • Order type
  • Position volume in lots
  • The price of discovery
  • Slippage in pips
and so on. The parameters passed to the function can be of two types: those that do not change in any way during the operation of the called function, and those that can be processed in it.
For example, let's consider the following function:

//+------------------------------------------------------------------+
//|  fill array of strings                                           |
//+------------------------------------------------------------------+
void SplitString(string &ArrayRes[],string InputString,string splitter)
  {
   string temp,tempArray[100];
   int pos,splitLength=StringLen(splitter),InputStrLength=StringLen(InputString),counter;
 
   pos=StringFind(InputString,splitter);
   if (pos!=-1)
      {
      if (pos==0) InputString=StringSubstr(InputString,splitLength,InputStrLength-splitLength);
      while (StringFind(InputString,splitter)!=-1)
         {
         pos=StringFind(InputString,splitter);
         InputStrLength=StringLen(InputString);
         tempArray[counter]=StringSubstr(InputString,0,pos);
         InputString=StringSubstr(InputString,pos+splitLength,InputStrLength-splitLength-pos);
         counter++;
         }
      if (StringLen(InputString)!=0)
         {
         tempArray[counter]=InputString;
         counter++;
         }   
      }
   ArrayResize(ArrayRes,counter);
   for (int i=0;i<counter;i++)  
      {
      ArrayRes[i]=tempArray[i];
      Print("i=",i,"   string=",ArrayRes[i]);
      }
   return;   
  }
Three parameters are passed into SplitString(): an ArrayRes array by reference (preceded by an ampersand &) and two formal parameters InputStrung (the string to be split into parts) and splitter (which is the splitter for splitting).
When the function is executed, the ArraRes array will contain several strings. The function itself in MQL4 cannot return complex types (e.g. array), but by using passing the parameters by reference, we avoid this restriction.

The full script is as follows :

//+------------------------------------------------------------------+
//|                                                        Split.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net/ru/"
 
 
//+------------------------------------------------------------------+
//|  fill array of strings                                           |
//+------------------------------------------------------------------+
void SplitString(string &ArrayRes[],string InputString,string splitter)
  {
   string temp,tempArray[100];
   int pos,splitLength=StringLen(splitter),InputStrLength=StringLen(InputString),counter;
 
   pos=StringFind(InputString,splitter);
   if (pos!=-1)
      {
      if (pos==0) InputString=StringSubstr(InputString,splitLength,InputStrLength-splitLength);
      while (StringFind(InputString,splitter)!=-1)
         {
         pos=StringFind(InputString,splitter);
         InputStrLength=StringLen(InputString);
         tempArray[counter]=StringSubstr(InputString,0,pos);
         InputString=StringSubstr(InputString,pos+splitLength,InputStrLength-splitLength-pos);
         counter++;
         }
      if (StringLen(InputString)!=0)
         {
         tempArray[counter]=InputString;
         counter++;
         }   
      }
   ArrayResize(ArrayRes,counter);
   for (int i=0;i<counter;i++)  
      {
      ArrayRes[i]=tempArray[i];
      Print("i=",i,"   string=",ArrayRes[i]);
      }
   return;   
  }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   string strInfo="aae|aer3|dzse|faw323";
   string strResult[] ;
   
   SplitString(strResult,strInfo,"|");
   
   int N=ArraySize(strResult);
   if (N>0)
      {
      for (int i=0;i<N;i++) Print("strResult[",i,"]=",strResult[i]);
      }
//----
   return(0);
  }
//+------------------------------------------------------------------+
Run it in your environment and see the result.
 
Here's another unfortunate piece of documentation

double OrderClosePrice( )
Returns the closing price of the selected order.
The order must be preselected using OrderSelect().
Example:
 if(OrderSelect(10,SELECT_BY_POS,MODE_HISTORY)==true) { datetime ctm=OrderOpenTime(); if(ctm>0) Print("Open time for the order 10 ", ctm);
     ctm=OrderCloseTime(); if(ctm>0) Print("Close time for the order 10 ", ctm); } else Print("OrderSelect failed error code is",GetLastError());

The description is on the OrderClosePrice function, while the example is on the OrderClosePrice function.
That's probably why 99% of the Expert Advisors we review do an absolutely unnecessary analysis of the order type
if(OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 0);
When you could just write
OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0)
 
Yes, that's a point I picked up on last week. I think something like that :

 if(OrderSelect(10,SELECT_BY_POS,MODE_HISTORY)==true)
    {
     datetime  ctm= OrderOpenTime();if(ctm>0)
     Print("Open time for the order 10 ", TimeToStr(ctm)); 
     double price=OrderClosePrice();
     if(price>0) Print("Close price for the order 10 ", DoubleToStr(price,MarketInfo(OrderSymbol(),MODE_DIGITS)));
    }
  else
    Print("OrderSelect failed error code is",GetLastError());
 
Quote
------
Three parameters are passed to SplitString(): ArrayRes array by reference (with ampersand & in front) and two formal parameters InputStrung (the string to be parsed) and splitter (which is the splitter for parsing).
When the function is executed, the ArraRes array will contain several strings. The function itself in MQL4 cannot return complex types (e.g. array), but by using passing the parameters by reference, we avoid this restriction.
------

I understand that. I don't understand why you called them "formal". Are these parameters that are passed just for fun, purely formally? There's no such thing in C.

Why is the description of parameter types described in the "Variables" section and not in the "Functions" section?
 
cout:
I understand that. I don't understand why you call them "formal". Are they parameters that are just passed around, purely formally? There is no such thing in C.


Because the variables passed into a function are passed there formally, not as variables, but as their values. Variables can be manipulated (their values changed), while such manipulations with values are meaningless.
Here is another version of this example:

//+------------------------------------------------------------------+
//|                                                        Split.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net/ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "https://www.metaquotes.net/ru/"
 
 
//+------------------------------------------------------------------+
//|  fill array of strings                                           |
//+------------------------------------------------------------------+
void SplitString(string &ArrayRes[],string InputString,string splitter)
  {
   string temp,tempArray[100];
   int pos,splitLength=StringLen(splitter),InputStrLength=StringLen(InputString),counter;
 
   pos=StringFind(InputString,splitter);
   if (pos!=-1)
      {
      if (pos==0) InputString=StringSubstr(InputString,splitLength,InputStrLength-splitLength);
      while (StringFind(InputString,splitter)!=-1)
         {
         pos=StringFind(InputString,splitter);
         InputStrLength=StringLen(InputString);
         tempArray[counter]=StringSubstr(InputString,0,pos);
         InputString=StringSubstr(InputString,pos+splitLength,InputStrLength-splitLength-pos);
         counter++;
         }
      if (StringLen(InputString)!=0)
         {
         tempArray[counter]=InputString;
         counter++;
         }   
      }
   ArrayResize(ArrayRes,counter);
   for (int i=0;i<counter;i++)  
      {
      ArrayRes[i]=tempArray[i];
      Print("i=",i,"   string=",ArrayRes[i]);
      }
   InputString="Входная строка";
   splitter="разделитель";
   Print("InputString=",InputString,"    splitter=",splitter);
   return;   
  }
 
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   string strInfo="aae|aer3|dzse|faw323";
   string strResult[] ;
   string devider="|";
   SplitString(strResult,strInfo,devider);
   
   int N=ArraySize(strResult);
   if (N>0)
      {
      for (int i=0;i<N;i++) Print("strResult[",i,"]=",strResult[i]);
      }
   Print("strInfo=",strInfo,"    devider=",devider);   
//----
   return(0);
  }
//+------------------------------------------------------------------+
 
So, call them "Passing parameters by value".
Formally means that nothing depends on its value, e.g. reserved for future use :). But parameters passed by value do depend on something, otherwise they would be called formal :).
Reason: