Библиотеки: MT4Orders - страница 56

 
SysFX:

I have an MT4 EA that I'm trying to port to MT5 using MT4Orders so I can maintain a single source, but I've run into some issues ...

1) when an order hits SL or TP, the usual [sl] or [tp] texts are not appended to the order comment if the EA added a comment during OrderSend().

Is this normal MT5 behaviour? If so, is there a reliable way to determine whether an order actually hit SL/TP or was closed manually?

(trying to decide by checking open price / close price / SL / TP is not reliable due to slippage - especially if SL was moved very close to TP)

https://www.mql5.com/ru/forum/93352/page20#comment_7112531

https://www.mql5.com/ru/forum/93352/page18#comment_6246123

2) when a partial close occurs, the comments on the open and closed portions order do not show "to #xxxxxxx" and "from #xxxxxxx"

again, is there a reliable (and hopefully simple) way to determine what happened to a particular order?

По этому описанию не понял, какую задачу нужно решить.

3) the ticket number of an open trade changes when it closes, so I can't use OrderTicket() to follow an order, but OrderTicketID() seems to work like OrderTicket() does in MT4 and retains the same ID for a closed trade.

Is that value constant, or might it change between platform restarts? If constant, what's the best way to use OrderTicketID() but retain compatibility with MT4 (since OrderTicketID() is not an MT4 function)?

** OrderTicketID() seems to ignore the MT4_TICKET_TYPE directive and is always "long"

SELECT_BY_TICKET работает правильно с OrderTicket/OrderTicketID/OrderTicketOpen. Все функции из MT4Orders не изменяют своих значений после перезагрузки Терминала.

Одинаковый OrderTicketID в MT5 может иметь несколько закрытых позиций (при частичном закрытии). По той же причине одинаковый OrderTicketID может быть у открытой позиции и у закрытой позиции. Из-за этой неоднозначности MT5 используется OrderTicket - уникальный для каждой закрытой/открытой позиции тикет.


Для кроссплатформенности (совместимости с MT4) было сделано это обновление библиотеки.


** OrderTicketID() seems to ignore the MT4_TICKET_TYPE directive and is always "long"
Спасибо, исправил.
// Список изменений:
// 11.11.2020
//   Fix: OrderTicketID() и OrderTicketOpen() возвращают заданный в TICKET_TYPE тип значения.
 
2) when a partial close occurs, the comments on the open and closed portions order do not show "to #xxxxxxx" and "from #xxxxxxx"

again, is there a reliable (and hopefully simple) way to determine what happened to a particular order?

What I meant was this:

If you have a 1.00 lot trade in MT4 with a ticket number 123456 and you partially close 0.40 lots, then ticket number 123456 shows on the History tab as 0.40 lots and its trade comment shows "to #NewTicket".

On the Trades tab, a new 0.60 lot trade appears with ticket number "NewTicket", and its trade comment shows "from #123456".

 
SysFX:

What I meant was this:

If you have a 1.00 lot trade in MT4 with a ticket number 123456 and you partially close 0.40 lots, then ticket number 123456 shows on the History tab as 0.40 lots and its trade comment shows "to #NewTicket".

On the Trades tab, a new 0.60 lot trade appears with ticket number "NewTicket", and its trade comment shows "from #123456".

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

#define Ask SymbolInfoDouble(_Symbol, SYMBOL_ASK)

void OnStart()
{
  const TICKET_TYPE Ticket = OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0);
  
  if (OrderSelect(Ticket, SELECT_BY_TICKET))
    OrderClose(OrderTicket(), 0.4, OrderClosePrice(), 0);
}

Этот скрипт создает вашу ситуацию. Напишите четко, что в этой ситуации нужно получить?

 
fxsaber:

This script creates your situation. Write clearly what you need to get in this situation?

So, in the tester, the following line would create ticket #2 (opening deposit is #1)

const TICKET_TYPE Ticket = OrderSend(_Symbol, OP_BUY, 1, Ask, 0, 0, 0);

Then, when this next line executes, a new ticket (#3) should open for 0.6 lots and ticket #2 should appear in order history as a 0.4 lot trade.

OrderClose(OrderTicket(), 0.4, OrderClosePrice(), 0);

In MT4, the order comment for #2 would be "to #3" and the order comment for #3 would be "from #2".

This doesn't happen in MT5 - the comment does not show on the Trades / History tabs, and OrdersToString() just shows "0" for the trade comment.

The same functionality should exist for the tester and for actual trading - I only mentioned the tester because the ticket numbers can be anticipated.

 
SysFX:

In MT4, the order comment for #2 would be "to #3" and the order comment for #3 would be "from #2".

This doesn't happen in MT5 - the comment does not show on the Trades / History tabs, and OrdersToString() just shows "0" for the trade comment.

Как вы уже заметили, при частичном исполнении MT5 не создает определенных комментариев, как это происходит в MT4.


MT4Orders никогда не будет эмулировать какое-либо поведение MT4. Эта библиотека предназначена для использования MT4-style торгового API в MT5. Не больше и не меньше.

Это значит, что если вы знаете MT4, то без труда напишите торговую логику в MT5.


Если вам нужно учесть какие-то тонкие особенности каждой платформы, то для этого есть макросы.

#ifdef __MQL5__
  // MQL5-code is here.
#else // #ifdef __MQL5__
  // MQL4-code is here.
#endif // #ifdef __MQL5__ #else


Если есть какая-то задача, которую не получается решить в MT5, то здесь люди могут помочь. Многое можно сделать через MT4Orders.

 
fxsaber:

Как вы уже заметили, при частичном исполнении MT5 не создает определенных комментариев, как это происходит в MT4.


MT4Orders никогда не будет эмулировать какое-либо поведение MT4. Эта библиотека предназначена для использования MT4-style торгового API в MT5. Не больше и не меньше.

Это значит, что если вы знаете MT4, то без труда напишите торговую логику в MT5.


Если вам нужно учесть какие-то тонкие особенности каждой платформы, то для этого есть макросы.


Если есть какая-то задача, которую не получается решить в MT5, то здесь люди могут помочь. Многое можно сделать через MT4Orders.

Yes ... I realised that it was caused by MT5 behaviour and have found a solution to that issue. It was more important for me to resolve the [sl] / [tp] problem and that is now working nicely - thank you for the information :)

 
Копирую и получаю пустой архив
 
grin4k:
Копирую и получаю пустой архив

Да, он пустой. Глюк сайта.

Но не загружайте архив, если код обновлялся. Зип не обновляется. Качайте пофайлово.

 
fxsaber :

Интересный случай MT5.


Тейк исполнился частично, после чего был удален. В этом случае имеем ситуацию, что DEAL_ORDER имеет статус ORDER_STATE_CANCELED, а не FILLED/PARTIAL.

При этом еще DEAL_TIME_MSC не равен ORDER_TIME_DONE_MSC.

Что было за ORDER_TYPE_FILLING в этом случае?

Я торгую через цензуру брокера url. При установке Take Profit значение по умолчанию ORDER_TYPE_FILLING == ORDER_FILLING_IOC. Ваше дело не должно происходить с МОК, верно?

 
Как обрабатывать ошибки - GetLastError, и ERR_INVALID_PRICE, ERR_PRICE_CHANGED, ERR_REQUOTE, ERR_OFF_QUOTES, ERR_TRADE_CONTEXT_BUSY - константы не определены.