Questions from Beginners MQL4 MT4 MetaTrader 4 - page 29

 
yaaarik777:

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);
  }
}
 
Vladimir Zubov:

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?

if (type > 1 && type < 6)
   {
     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. This is clearly an obstacle, because the line did not break yesterday at 14:00 on MT4.
Files:
image.png  82 kb
image.png  81 kb
 
Good afternoon! could you please tell me, I downloaded the mt4 636 version on android, but it does not see the list of brokers. Is the terminal version no longer supported?(( If so, where can i download a working one?
 
MetaGSss:
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.
They want you to know in advance where the price will go
 
MetaGSss:
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.
the spread is for extreme people of course)))
 
MetaGSss:
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.
the symbols are also slightly different)
 

- последние четыре строчки в общем понятны, вопрос лишь в функции PlaySound,  код которой необходимо вставить после каждой строчки "Print("..." в таком виде: 

bool PlaySound(

string payment // file name

)

; ...

Or is it also converted somehow?

Declare

bool PlaySound( in program header - you will get an opportunity to turn on and off sound in set file extern bool Play = TRUE;

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) ?






ThanksA1exPit for the detailed and clear reply ... "The point of the action" is to sound the events of "closing orders at Takeprofit and Staploss" = a different sound for each ...
 

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.

Reason: