Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 403

 
Link_x:
Point by point answer, sorry.
1 - programming genius?
2 - to be fair, nothing is superfluous except feces and other decay products (frank opinion, ready to start debating, but in another thread :) ).
3 - it all makes sense now. :)
4 - so true. I know. I got a bit "wrong" and typed with the "OrderSend" function.

Thank you for contributing to the "Function Bricks Parsing" template. :)

1. let's dispense with the sarcasm, shall we? It made your learning comfortable and easy. What's genius got to do with it?
2. Argumentative.
3. You don't understand a damn thing, judging by your comments in the code.
4. It happens.

int GetTypeLastClosePos(string sy="", int mn=-1) {    
   datetime t;                                        // Переменная хранит время закрытия
   int      i, k=OrdersHistoryTotal(), r=-1;          // Объявление переменных i - индекс k - количество ордеров в истории r - будет хранить тип ордера
   if (sy=="0") sy=Symbol();                          // Если в функцию в качестве значения символа передан NULL, то будет использоваться текущий символ графика
   for (i=0; i<k; i++) {                              // Цикл по истории от нуля до OrdersHistoryTotal()
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { // Если ордер с индексом i выбран в истории
// ---------------------- определение нужного нам ордера ордера ---------------------               
         if ((OrderSymbol()==sy || sy=="") &&         // если переданный символ совпадает с символом ордера или передано значение по-умолчанию
             (mn<0 || OrderMagicNumber()==mn)) {      // если передано значение по-умолчанию или магик ордера равен переданному в функцию значению
            if (OrderType()==OP_BUY || OrderType()==OP_SELL) { // если это или Buy или Sell
// --------------------- определение последнего закрытого ордера --------------------               
               if (t<OrderCloseTime()) {                       // если значение, записанное в t меньше времени закрытия ордера
                  t=OrderCloseTime();                          // запоминаем значение времени закрытия выбранного ордера для следующего сравнения
                  r=OrderType();                               // запоминаем тип ордера
                  }                                            // Конец блока определения времени закрытия.
               }                                               // Конец блока обработки найденного нужного ордера по типу (одного из возможных)
            }                                                  // Конец блока проверки по символу и магику
         }                                                     // Конец блока обработки выбранного ордера
      }                                                        // Идём проверять следующий ордер (если i всё ещё меньше k)
// -- после прохода в цикле по всей истории в r будет лежать тип ордера или -1 (если не нашли ничего) --               
   return(r);                                                  // возвращаем результат поиска (либо тип ордера, либо -1)
}                                                              // Аминь. 

On point 2, an example:

int GetTypeLastClosePos(string sy, int mn) {    
   datetime t;                                        // Переменная хранит время закрытия
   int      i, k=OrdersHistoryTotal()-1, r=-1;        // Объявление переменных i - индекс k - количество ордеров в истории r - будет хранить тип ордера
   for (i=k; i>=0; i--) {                             // Обратный цикл по истории от OrdersHistoryTotal()-1 до нуля 
      if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { // Если ордер с индексом i выбран в истории
// ---------------------- определение нужного нам ордера ордера ---------------------               
         if(OrderMagicNumber()!=mn) continue;         // если магик не тот - идём выбирать следующий ордер в истории
         if(OrderSymbol()!=sy)      continue;         // если переданный символ не равен символу ордера - идём выбирать следующий ордер в истории
         if (OrderType()>1)         continue;         // если это не Buy и не Sell - идём выбирать следующий ордер в истории
// --------------------- дальше имеем выбранный нужный нам ордер --------------------        
// -------------------------- определяем время его закрытия -------------------------               
         if (t<OrderCloseTime()) {                    // если значение, записанное в t меньше времени закрытия ордера
            t=OrderCloseTime();                       // запоминаем значение времени закрытия выбранного ордера для следующего сравнения
            r=OrderType();                            // запоминаем тип ордера
            }                                         // Конец блока определения времени закрытия.
         }                                            // Конец блока обработки выбранного ордера
      }                                               // Идём проверять следующий ордер (если i всё ещё больше k)
// -- после прохода в цикле по всей истории в r будет лежать тип ордера или -1 (если не нашли ничего) --               
   return(r);                                         // возвращаем результат поиска (либо тип ордера, либо -1)
}                                                     // Аминь. 

There are less unnecessary things

 
Link_x:

Here is an example of practical use of a custom function:

.
Thank you.
So you have to apply the name of the function to use it, and the variable "r" itself is set to determine the value of that function!
Here's a little discovery for me! ^^
Thanks again, Yuri. :)


For a final clarification, this is possible:

?


Your examples are not correct. When you call a function that has parameters, you must give the values of those parameters in brackets, separated by commas. You should also know that not all the functions are assigned values. If the function type is void, it has no meaning and is intended to perform some action or calculate some variables. In the latter case, it is necessary to know the names of these variables, in order to use the results of this function.

 
Link_x:

if(GetTypeLastClosePos == OP_BUY)

The compiler will give you an error on this line that the variable is not declared.

you should at least do this:

if(GetTypeLastClosePos() == OP_BUY)
 
artmedia70:

On point 2, an example:

There are fewer unnecessary items



Sorry for the silly question, but why are you digging through the entire history to find the last closed order? You find the first one from the end and get right out, I guess.
 
Roger:


Sorry for the silly question, but why are you digging through history to find the last closed order? You find the first one from the end and immediately exit, as I understand it.
Once there was a discussion about a problem when the history was stored in the form in which the user sorted it. Hence (to be sure) the search is exactly like that.
 
artmedia70:
There was once a discussion about a problem where the history was stored as the user sorted it. Hence (to be safe) the search is exactly like that.

The user can only sort the history for visual perception, the position numbers in the history cannot be changed.
 
Roger:
The user can only sort the story visually, the position numbers in the story cannot be changed.

This is a good thing. But it used to be different. Now I will not look for information on the forum - it was a long time ago. So I wondered, what if it happens again? I would rather run through the orders than get a wrong result.
 
Roger:
The user can only sort the story visually, the position numbers in the story cannot be changed.

Actually, one can only really hope for order in the tester.
 
TheXpert:
Actually, one can only really hope for order in the tester.


Haven't noticed, but okay, I won't argue. Make the depth 10-20, should be enough. But the whole story... That's a bit much, in my opinion.
 
fenix74:
evillive, tried to replace as you said, but I guess even this requires a little more knowledge, compiling gives "53 error(s), 18 warning(s)", the result is attached. evillive, can I ask you to make these replacements, if you have time.

You just need to be more attentive, or don't be lazy to specify the variable type on each line, or put a comma instead of a semicolon. And in indicator calls variables must be defined, not just from a torch.


Here is an example, and then - on your own...

Although the second file seems to be ok, except for a dot in a variable name. No dots in variable names.

Reason: