Dear mql4 gurus. Please help me write a function for removing postponements, after a given number of seconds, how to implement it over time, I can not understand… it is not necessary to write the entire function, I can not make the very condition that if for example 10 seconds have passed since the installation of the delay, then it must be removed. That’s something like that.
Share
knelson
Hello, tell me, there is such a function that it would be possible to transfer a pending order for a certain number of pips, not to trawl the order and transfer it once to the distance that is set in the settings. Sincerely, Alexander.
aziriz
exactly)) thank you very much to everyone)
vitales
You can do that. You just work with the same type of datetime variables. In my version, variables of different types are datetime and int.
aziriz
that’s exactly what I did, but why do I have a difference?. the time and time of opening turns out to be like this 1970.01.01 00:00:51
as I understand it, you should get a number in seconds, for example, 5 seconds or 10. But it turns out this date
vitales
if ((uint)(TimeCurrent()-OrderOpenTime())
This piece just calculates the difference between the current time and the order opening price, and this difference will be in seconds, since datetime variables store date and time data in the form of the number of seconds that have passed since 1.01.1970.
If it is necessary in minutes, then multiply the TimeLimit by 60 if in hours, then by 3600 (the number of seconds in one hour)
If the difference between TimeCurrent()-OrderOpenTime () is less than TimeLimit, then the time has not expired yet, if it is more, then the rest of the code is executed, where the order type is checked and deleted.
To avoid bothering with type casting change the type of the TimeLimit variable from uint to int and then this piece will look like this:
if ((TimeCurrent()-OrderOpenTime())
aziriz
it does not work for me, in the second function, the condition for checking the difference between the opening time and the current time, if some calculations occur with this data, the date is reset to 1970
I don’t understand why you can’t just take and subtract the opening time from the current time and whatever value you get there.
how do I do this? if using the example of the second function to get the difference in seconds would be very great
vitales
void DeleteAllOrder(int Cmd, uint TimeLimit)
Try this feature.{
int count=OrdersTotal();
if (count<=0) return;
for (int i=Count;i>=1;i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if ((uint)(TimeCurrent()-OrderOpenTime())continue;
if (Cmd==-1)
{
if (OrderType()==OP_BUYLIMIT || OrderType()==OP_BUYSTOP ||
OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)
OrderDelete(OrderTicket());
}else
if (OrderType()==Cmd) OrderDelete(OrderTicket());
}
}
}
/ / Cmd-order type, if -1, then all pending orders.
//TimeLimit life time of the order. for example, if you need to set the lifetime to 1 hour, the TimeLimit should be 1*3600