Questions from Beginners MQL4 MT4 MetaTrader 4 - page 14

 
Alexey Kozitsyn:
Let's put it this way. You show the code that goes through the orders with an explanation of how it should do this and only then we will be able to say what is right and what is wrong. Just the names of functions will not help you get closer to the result.

Hello ... thanks for agreeing to help me ... It seemed like a small undertaking, to sound orders closing, could be done simply by adding the required event to the appropriate folder - it turned out to be not so easy ... Here is a sample code I took fromMQL4 ReferenceTrading Functions:

intOrdersHistoryTotal();

// retrieving info from trade history
int i,accTotal=OrdersHistoryTotal();
for(i=0;i<accTotal;i++)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Error accessing the history database (",GetLastError(),"));
break;
}
// working with an order ...

}

... The function returnsthe amount of closed and deleted orders in the history of the current account loaded in the client terminal. The size of the history list depends on the current settings of the "Account History" tab of the terminal.

How it will search through them and why it is needed is not clear to me... Perhaps, it is necessary to memorize them and discard them, so that they do not get in the way?

We are supposed to sound newly closed orders the moment they are closed with a short beep. All orders to be closed in my Client Terminal are of two types only: byTrailStopLoss andTakeProfit averaging. When closing an order (a group of orders), no matter which direction (Sell or Buy) they should be separated only byStopLossorTakeProfit andsent to the correspondingPlaySoundfunction.

Справочник MQL4
Справочник MQL4
  • docs.mql4.com
Справочник MQL4
 
bablusut:

Hello ... thanks for agreeing to help me ... It seemed like a small undertaking, to sound orders closing, could be done simply by adding the required event to the appropriate folder - it turned out to be not so easy ... Here is a sample code I took fromMQL4 ReferenceTrading Functions:

intOrdersHistoryTotal();

// retrieving info from trade history
int i,accTotal=OrdersHistoryTotal();
for(i=0;i<accTotal;i++)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Error accessing the history database (",GetLastError(),"));
break;
}
// working with an order ...

}

... The function returnsthe amount of closed and deleted orders in the history of the current account loaded in the client terminal. The size of the history list depends on the current settings of the "Account History" tab of the terminal.

How it will search through them and why it is needed is not clear to me... Perhaps, it is necessary to memorize them and discard them, so that they do not get in the way?

We are supposed to sound newly closed orders the moment they are closed with a short beep. All orders to be closed in my Client Terminal are of two types only: byTrailStopLoss andTakeProfit averaging. When closing an order (a group of orders) no matter which direction (Sell or Buy) they should be separated only by theStopLossorTakeProfitclosing commandand sent to the correspondingPlaySoundfunction.

The order should be searched in reverse order, since 0 is the very first. accTotal-1 is the last. In this code, after "// work with order", memorize the comment and check if there is a closing comment on the SL or TP.
 
Alexey Kozitsyn:
Orders should be searched in the reverse order since 0 is the very first. accTotal-1 is the last. In this code, after "// work with order" remember the comment and check if there is a closing comment for the SL or TP.

intOrdersHistoryTotal();

// retrieving info from trade history
int i,accTotal=OrdersHistoryTotal();
for(i=0;i<accTotal;i++)
{
//---- check selection result
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
{
Print("Error accessing the history database (",GetLastError(),"));
break;
}
// working with an order ...

}

stringOrderComment();

stringcomment;
if(OrderSelect(10,SELECT_BY_TICKET)==false)
{
Print("OrderSelect() has returned an error ",GetLastError());
return(0);
}
comment=OrderComment();

// ...

Thanks for the reply ... After adding the code of theOrderComment function,(MQL4Trading FunctionsReference) which returns the comment of an order selected using the OrdersHistoryTotal function, the code looks like this ... but don't we have a function that tracks new closed orders in the terminal history?"0 - very first. accTotal-1 - last" - we mean "first closed" and "last closed" in the terminal history, is it by time ...? did I get it right?


Справочник MQL4
Справочник MQL4
  • docs.mql4.com
Справочник MQL4
 
bablusut:

but do we not have a function to track new closed orders in the terminal history?

There are no standard ones.

  int i,accTotal=OrdersHistoryTotal();
  string comment;
  for(i=accTotal-1;i>=0;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
        break;
       }
     // работа с ордером ...
     comment = OrderComment();
     // Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
    }
To determine the presence of one line in another - use the functions of working with lines.
 
Alexey Kozitsyn:

There are no standard ones.

  int i,accTotal=OrdersHistoryTotal();
  string comment;
  for(i=accTotal-1;i>=0;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
        break;
       }
     // работа с ордером ...
     comment = OrderComment();
     // Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
    }
To determine if one string is present in the other - use string functions.

Thank you ... You mean the function StringFind = Search for a substring in a string.

int StringFind(
string string_value, //the string we are searching for
string match_substring, //what we are searching for
int start_pos=0 //where to start search

);

Parameters
string_value
[in] String to search in.
match_substring
[in] Match_substring to be searched.
start_pos=0
[in] Position in the string where the search should be started.
Returned value

Returns position number in the string where the substring to be searched starts, or -1 if no substring is found.

... orStringCompare function -Compares two strings?...


StringCompare - Строковые функции - Справочник MQL4
StringCompare - Строковые функции - Справочник MQL4
  • docs.mql4.com
StringCompare - Строковые функции - Справочник MQL4
 
bablusut:

Thank you ... You mean the function StringFind = Search for a substring in a string.

int StringFind(
string string_value, // the string we are searching for
string match_substring, //what we are searching for
int start_pos=0 //where to start search

);

Parameters
string_value
[in] String to search in.
match_substring
[in] Match_substring to be searched.
start_pos=0
[in] Position in the string where the search should be started.
Returned value

Returns position number in the string where the substring to be searched starts, or -1 if no substring is found.

...


True.
 
Alexey Kozitsyn:
Correct.

Thank you ... the code will then go on to look like this:

 int i,accTotal=OrdersHistoryTotal();
  string comment;
  for(i=accTotal-1;i>=0;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
        break;
       }
     // работа с ордером ...
     comment = OrderComment();
     // Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
    }

int  StringFind(
   string  string_value,        // строка, в которой ищем
   string  match_substring,     // что ищем
   int     start_pos=0          // с какой позиции начинать поиск

   ); 



 

 
bablusut:

Thank you ... the code will then take the form of:

 int i,accTotal=OrdersHistoryTotal();
  string comment;
  for(i=accTotal-1;i>=0;i++)
    {
     //---- check selection result
     if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false)
       {
        Print("Ошибка при доступе к исторической базе (",GetLastError(),")");
        break;
       }
     // работа с ордером ...
     comment = OrderComment();
     // Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
    }

int  StringFind(
   string  string_value,        // строка, в которой ищем
   string  match_substring,     // что ищем
   int     start_pos=0          // с какой позиции начинать поиск

   ); 



 

No. Try to understand what you are doing. What you have written is just a prototype function (i.e. just a description of what it does). So you just ripped out a piece of documentation. You need to use it. So you have to substitute your own values for arguments. And the function will return the result. Then this result must be processed.
 

Forum on trading, automated trading systems and trading strategy testing

Questions from Beginners

A1exPit, 2016.11.30 22:14

Can you tell me OrderSelect by SELECT_BY_POS which 0 order is the last placed or the first? I am trying it both ways and vice versa, but the error modify #0 is flying out.

 
Vladimir Karputov:

let's look at the code.
Reason: