Questions from Beginners MQL4 MT4 MetaTrader 4 - page 249

 
Taras Slobodyanik #:

The point is that operators can be translated into assembler without using functions, by simple processor commands - these are the operators.

What is more complex, what requires calling complex procedures is a function.

about the gist, a function is a CALL in assembler and it's a hardware implementation that saves the sec address on the stack, then the function parameters are programmatically passed on the stack, local function variables are also allocated on the stack....

i.e. a function call is a certain sequence of actions, tied to the language and hardware conventions of the PC


And operators... to be honest, I learned more from Wiki now than I did before the discussion

 
Igor Makanu #:

well, if to get to the point, function is CALL in assembler and it is hardware implementation, which saves secant address on stack, then function parameters are programmatically transferred to stack, local function variables are also allocated on stack....

i.e. a function call is a certain sequence of actions, tied to the language and hardware conventions of the PC


and operators..., to be honest, I learned more from the wiki now than before the discussion

CALL is a call (operator), not the function itself.

i.e. a function is a large number of operators)

 
Taras Slobodyanik #:

CALL is a call (operator), not the function itself.

i.e. a function is a large number of operators)

and if there is only one operator, then it is not a function?

void OnStart()
{
   int x = 0;
   inc(x);
}
//+------------------------------------------------------------------+
void inc(int &v)
{
   v = v + 1;
}
 
Igor Makanu #:

and if there is one operator, then it is not a function?

The question was about "if" and "alert".
why is the first an operator and the second a function?

The word "alert" itself is also an operator - but it's a word that calls a function)

and the word "if" does not call a function.

function is many words (operators)

 
Gentlemen, thank you for your answers, there is a lot of discussion. Unfortunately, I am not able to understand most of it, because you use deep terms, which I have not met in the textbook yet.

From the answer of Maxim and Taras I can conclude that the terminological apparatus in the language is not strict and there are assumptions, calling some operators as functions. Based on the answer that an operator is one word and a function has many words, it also becomes unclear that the same "if" operator can have many words/actions in regular and curly brackets.
 
Ivan Butko #:
Gentlemen, thank you for your answers, the discussion started. Unfortunately I can't understand most of it, because you use deep terms which I haven't encountered in the textbook.

From the answer of Maxim and Taras I can conclude that the terminology in the language is not strict and there are assumptions, calling some operators as functions. Based on the answer that an operator is one word and a function has many words, it also becomes unclear that the same "if" operator can have many words/actions in regular and curly brackets.

a function is a subprogram.
an operator is a program word.

A function is made so that you don't have to write many identical operators each time, and call it many times.

Calling a function to execute a single operator makes no sense, because it can be done at once.


ps. Alert is a function (subprogram) written by the developers so that everyone can use it.

 
Taras Slobodyanik #:

a function is a subprogram.
an operator is a program word.

A function is made so that you don't have to write many identical operators each time, and call it many times.

Calling a function to execute a single operator makes no sense, because it can be done at once.


ps. Alert is a function (subroutine) written by the developers for everyone to use.

Exactly, Alert has a description that's hidden as a feature of the function. Reread the section, noticed that.

Thanks for the clarification, I think there is no more dissonance in my head on this issue

 
double CalculateProfitHistory() 
{
   double profit = 0;
   int cnt = LockTicket, i , ototal = OrdersHistoryTotal();
   for(i = 0; i < ototal; i++)
     {
      if(OrderSelect(cnt, SELECT_BY_TICKET, MODE_HISTORY))
        {
         if(OrderSymbol() == Symbol() && OrderCloseTime() > 0)
           {
            if(OrderType() == OP_BUY || OrderType() == OP_SELL)
              {
               if(OrderMagicNumber() == Magic )
                 {
                  profit += OrderProfit()+OrderCommission()+OrderSwap();
                                    
                 }
              }
           }
        }
     }
   return(profit);
}
Good afternoon. Please advise. Why is the calculation not correct? To be more precise, it shows the profit of the next order without adding it to the previous one.
The idea is to change the ticket from which they should go upwards, after a certain profit has been set.
 
Go through i and substitute cnt
 
Aleksei Stepanenko #:
Go through i and substitute cnt

write down the correct way.

Reason: