You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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 historyint 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.
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 historyint 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.
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 historyint 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?
but do we not have a function to track new closed orders in the terminal history?
There are no standard ones.
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();
// Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
}
There are no standard ones.
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();
// Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
}
Thank you ... You mean the function StringFind = Search for a substring in a string.
);
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?...
Thank you ... You mean the function StringFind = Search for a substring in a string.
);
Returns position number in the string where the substring to be searched starts, or -1 if no substring is found.
...
Correct.
Thank you ... the code will then go on to look like this:
int i,accTotal=OrdersHistoryTotal();
int StringFind(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();
// Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
}
string string_value, // строка, в которой ищем
string match_substring, // что ищем
int start_pos=0 // с какой позиции начинать поиск
);
Thank you ... the code will then take the form of:
int i,accTotal=OrdersHistoryTotal();
int StringFind(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();
// Проверяем, есть ли в комментарии признак закрытия ордера по ТП или СЛ
}
string string_value, // строка, в которой ищем
string match_substring, // что ищем
int start_pos=0 // с какой позиции начинать поиск
);
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.