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
Good day everyone! Can you please advise how to set an order deletion in an EA?
The situation is as follows:
We place 2pending orders in different directions, as soon as one of them triggers, the other is removed and is no longer exhibited.
I would be very grateful for any help.
Thank you.
For example:
// удаляет отложенные ордера по type +
//+------------------------------------------------------------------+
void DeleteOrders(int type)
{
int cnt = OrdersTotal();
for (int i=cnt-1; i>=0; i--) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
//По желанию
if (OrderSymbol() != Symbol()) continue;
//По желанию
if (OrderMagicNumber() != mn) continue;
if (OrderType() != type) continue;
if (type == OP_BUYSTOP || type == OP_SELLSTOP)
{
bool Del_1 = OrderDelete(OrderTicket());
if(!Del_1)
Print("Ошибка удаления ордера. Код ошибки=",GetLastError());
else
Print("Ордер успешно удален.");
}
if (type == OP_BUYLIMIT || type == OP_SELLLIMIT)
{
bool Del_2 = OrderDelete(OrderTicket());
if(!Del_2)
Print("Ошибка удаления ордера. Код ошибки=",GetLastError());
else
Print("Ордер успешно удален.");
}
}
}
//+------------------------------------------------------------------+
And before that, determine that there is a position and it is time to kill the extra order
//| Автор : Ким Игорь В. aka KimIV, http://www.kimiv.ru |
//+----------------------------------------------------------------------------+
//| Версия : 16.06.2008 |
//| Описание : Удаление ордеров, противоположных позиции |
//+----------------------------------------------------------------------------+
//| Параметры: |
//| sy - наименование инструмента ("" - любой символ, |
//| NULL - текущий символ) |
//| op - операция (-1 - любая позиция) |
//| mn - MagicNumber (-1 - любой магик) |
//+----------------------------------------------------------------------------+
void DeleteOppositeOrders(string sy="", int op=-1, int mn=-1) {
bool eb, es;
switch (op) {
case OP_BUY : eb=ExistPositions(sy, OP_BUY , mn); break;
case OP_SELL: es=ExistPositions(sy, OP_SELL, mn); break;
default: eb=ExistPositions(sy, OP_BUY , mn);
es=ExistPositions(sy, OP_SELL, mn); break;
}
if (eb) {
DeleteOrders(sy, OP_SELLLIMIT, mn);
DeleteOrders(sy, OP_SELLSTOP , mn);
}
if (es) {
DeleteOrders(sy, OP_BUYLIMIT, mn);
DeleteOrders(sy, OP_BUYSTOP , mn);
}
}
To give you an example:
// удаляет отложенные стоп ордера SELLSTOP или BUYSTOP по type +
//+------------------------------------------------------------------+
void DeleteOrders(int type)
{
int cnt = OrdersTotal();
for (int i=cnt-1; i>=0; i--) {
if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
//По желанию
if (OrderSymbol() != Symbol()) continue;
//По желанию
if (OrderMagicNumber() != mn) continue;
if (OrderType() != type) continue;
if (type == OP_BUYSTOP || type == OP_SELLSTOP)
{
bool Del_1 = OrderDelete(OrderTicket());
if(!Del_1)
Print("Ошибка удаления ордера. Код ошибки=",GetLastError());
else
Print("Ордер успешно удален.");
}
if (type == OP_BUYLIMIT || type == OP_SELLLIMIT)
{
bool Del_2 = OrderDelete(OrderTicket());
if(!Del_2)
Print("Ошибка удаления ордера. Код ошибки=",GetLastError());
else
Print("Ордер успешно удален.");
}
}
}
//+------------------------------------------------------------------+
What is the segregation by type? What does it do? Would it make a difference if written this way?
{
bool Del_1 = OrderDelete(OrderTicket());
if(!Del_1)
Print("Ошибка удаления ордера. Код ошибки=",GetLastError());
else
Print("Ордер успешно удален.");
}
Why are the bars different in mt4 and mt5 on my iPhone? Although the opening and closing times of the bars are the same. It obviously prevents you from breaking through the line yesterday at 14:00 on MT4.
Why are the bars different in mt4 and mt5 on my iPhone? Although the opening and closing times of the bars are the same. This obviously interferes because the line did not break through yesterday at 14:00 on mt4.
Why are the bars different in mt4 and mt5 on my iPhone? Although the opening and closing times of the bars are the same. It obviously interferes because the line was not broken yesterday at 14:00 on MT4.
- последние четыре строчки в общем понятны, вопрос лишь в функции PlaySound, код которой необходимо вставить после каждой строчки "Print("..." в таком виде:
bool PlaySound(
string payment // file name
)
; ...
Or is it also converted somehow?
Declare
further, what will Print print? And under what condition?
What is the point of this action? To play a sound when order is closed and to write a comment (on TP or SL) ?
Greetings. I've asked around, but haven't found an answer yet. Could you please tell me why with the following entry
if (x!=maxpr1){x=maxpr1; OrderDelete(ticketD);}
if (z!=minpr1){z=minpr1; OrderDelete(ticketUP);}
The system constantly generates errors
: invalid ticket for OrderDeletefunction
: OrderDelete error 4051
According to the reference book it is
Invalid value of the function parameter
Although the parameters seem to be the same.
Although if you remove the condition and leave only
OrderDelete(ticketD);
OrderDelete(ticketUP);
it deletes successfully (but I need it by condition). What I do wrong? Here is the whole thing:
https://www.mql5.com/ru/forum/160683/page31#comment_3911573
The Expert Advisor reads min and max values of the last X bars and places orders by these values. Then if the maximum or minimum has decreased, we should delete the corresponding order and open it using the new data.
I have just started to study it and deleting rather than modifying it was done to study the function and I wondered why it did not work.