Questions from Beginners MQL5 MT5 MetaTrader 5 - page 645
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
Assuming that the last order by time is not the last order in the list, your example is incorrect because it doesn't take into account the very first order (#0).
The ticket of the last order in time is found first, and then a cycle with modifications is made. When a previously found ticket of the last order is encountered in the loop, it is skipped.
To find the ticket of the last order, we don't need to search all of the history of all orders - we can set the size of the searched history - a day, two, three, a week... "And skip all orders with the time, which is earlier than the search range. For example: the size of the search history is set to 1 day - all orders, that were earlier than the current time - one day, are skipped. But we still need the cycle. If we take only the last order in the list, it can be Buy, and we need Sell. It is the last but one. Thus, we will not get his data.
The ticket of the last order in time is found first, and then a cycle with modifications is made. When a previously found ticket of the last order is encountered in the loop, it is skipped.
To search for the ticket of the last order, you don't need to run the entire history of all orders - you can set the size of the searched history - a day, two, three, a week... "And skip all orders with the time, which is earlier than the search range. For example: the size of the search history is set to 1 day - all orders, that were earlier than the current time - one day, are skipped. But we still need the cycle. If we take only the last order in the list, it can be Buy, and we need Sell. It is the last but one. Thus, we will not get his data.
Artem, thanks for the explanation of course, but I know how to find the order in the list. And my reply was not to you, but to Alexei on his example (in particular, that the condition "> 0" will not work).
You'd better write the right way (with code only). I'm lazy :)
If we suppose that the last order is not the last in the list, your example is incorrect because it doesn't consider the very first order (order 0).
How can it not?
Alexey Viktorov:
An additional variant: Before the loop, write in the variable _1 a ticket, for example, of a zero order, and then
void OnStart()
{
int i, t1, t2, modTicket , total = OrdersTotal();
datetime d1, d2;
if(OrderSelect(0, SELECT_BY_POS))
{
t1 = OrderTicket();
d1 = OrderOpenTime();
}
for(i = 1; i < total; i++)
{
if(OrderSelect(i, SELECT_BY_POS))
{
t2 = OrderTicket();
d2 = OrderOpenTime();
modOrder((d1 < d2) ? t1 : t2);
t1 = d1 < d2 ? t2 : t1;
d1 = d1 < d2 ? t2 : t1;
}
}
}/********************************************************************/
void modOrder(int ticket);
{
// здесь код модификации ордера.
}/********************************************************************/
How can it not?
void OnStart()
{
int i, t1, t2, modTicket , total = OrdersTotal();
datetime d1, d2;
if(OrderSelect(0, SELECT_BY_POS))
{
t1 = OrderTicket();
d1 = OrderOpenTime();
}
for(i = 1; i < total; i++)
{
if(OrderSelect(i, SELECT_BY_POS))
{
t2 = OrderTicket();
d2 = OrderOpenTime();
modOrder((d1 < d2) ? t1 : t2);
t1 = d1 < d2 ? t2 : t1;
d1 = d1 < d2 ? t2 : t1;
}
}
}/********************************************************************/
void modOrder(int ticket);
{
// здесь код модификации ордера.
}/********************************************************************/
If you take it as a starting variant, it will do, but it's better to do it from the end... Although, if we do not have to delete orders, we will be okay, too.
As a matter of fact, to modify several orders, you have to go through them in a loop. So it turns out that additional microseconds will be spent only on comparing the order open time. This will be an optimal variant.
The direction of the cycle ... It doesn't really matter because it's not about closing orders. I confused my previous version and wrote "close", so the loop was corresponding there as well...
Good afternoon!
I am trying my hand at writing an indicator. I want to get visually what I have wanted, but I want the indicator to send the required information, for example, textual information, or int type. How can I do it, taking into account that I have 10 buffers, according to which the lines are drawn? Thanks!
Good afternoon, do not kick me, but I found this heading and decided to ask a few questions ... I have a terminal ... I downloaded from one broker MT4 (1) ... ran the demo ... after some time registered at another, too
I was offered to download the terminal ... downloaded (2) as a result, 2 terminal does not go ... and 1 appeared profile 2 broker ... in general, all confused ... then from binary comes a letter that they move to MT5 ... installed and at first glance, all much better than the MT4 . My question is whether it is possible to open an account with different brokers on one terminal? and can i transfer all of them to mt5 ? and if indicators from MT4 suit to 5 ?
thanks ...
Such active help, thank you very much.
Already struggling with a new problem)
Please help me to find out the fact of new ZigZag vertex appearance.
I tried to store in a variable the price of the first vertex, then compare it, if the price has changed raise a flag, there is a new vertex.{
newZZH1_PR=GetExtremumZZPrice(Symbol(),T_F_,1);
newZZH1=true;
}
But it turned out that the function, over time, returns chaotically, then the price of the first vertex, then the second.
It turns out the new top is not formed and the flag is raised.{
if (sy=="" || sy=="0") sy=Symbol();
double zz;
int i, k=iBars(sy, tf), ke=0;
for (i=1; i<k; i++) {
zz=iCustom(sy, tf, "ZigZag", ExtDepth,ExtDeviation,ExtBackstep, 0, i);
if (zz!=0) {
ke++;
if (ke>ne) return(zz);
}
}
Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
return(0);
}
Such active help, thank you very much.
Already struggling with a new problem)
Please help me to find out the fact of new ZigZag vertex appearance.
Tried to remember in a variable the price of the first vertex, then compare, if the price has changed raise a flag, there is a new vertex.{
newZZH1_PR=GetExtremumZZPrice(Symbol(),T_F_,1);
newZZH1=true;
}
But it turned out that the function, over time, returns chaotically, then the price of the first vertex, then the second.
It turns out that no new vertex is formed, but the flag is raised.{
if (sy=="" || sy=="0") sy=Symbol();
double zz;
int i, k=iBars(sy, tf), ke=0;
for (i=1; i<k; i++) {
zz=iCustom(sy, tf, "ZigZag", ExtDepth,ExtDeviation,ExtBackstep, 0, i);
if (zz!=0) {
ke++;
if (ke>ne) return(zz);
}
}
Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
return(0);
}
The zigzag actually has three buffers - 0 total, 1 - the upper extremum, 2 - the lower extremum.
At the zero bar, there is always a value in some of the buffers - either in the first one (if the knee is up) or in the second one (if it is down). Accordingly, the zero buffer on the current candle always has a value - either from the first buffer or from the second one.
Well, to find a clear upper extremum, we should look for the first nonempty value of the first buffer, starting from bar 1. For the lower extremum, we need to find the first non-blank value of the second buffer, starting from bar 1.
In order to know if this is a new top or bottom, we need to remember the time of the previous top/top found, and compare it with what we have found so far.
It's rambling, but hopefully you'll understand...