Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1147

 
Vladimir Karputov:

There you go:


Another important thing is how you update prices (and do you update them at all?). The spread - how do you get it?

    double point, price, ask, bid;
    ulong digits;

    if(!SymbolInfoDouble(symbol, SYMBOL_ASK, ask)) return(true);
    if(!SymbolInfoDouble(symbol, SYMBOL_ASK, bid)) return(true);
    if(!SymbolInfoInteger(symbol, SYMBOL_DIGITS, digits)) return(true);
    if(!SymbolInfoDouble(symbol, SYMBOL_POINT, point)) return(true);
SymbolInfoInteger(symbol, SYMBOL_SPREAD);
 
Mikhail Sergeev:

So, for future reference:

1.SymbolInfoDouble

If this function is used to get information about the last tick, it is better to useSymbolInfoTick(). It's quite possible that there hasn't been any quote for this symbol since the time the terminal connected to the trading account. In this case, the requested value will be undefined.

2. It is better to take the spread as a difference between Ask and Bid.

3. Level of freeze: look for the maximum valueout of three (SYMBOL_TRADE_FREEZE_LEVEL, SYMBOL_TRADE_STOPS_LEVEL and calculated spread) and multiply by three and you will be happy.

Point 3 was deduced in practice when working with KodoBase (and the validator in both KodoBase and Market is the same).
Документация по MQL5: Получение рыночной информации / SymbolInfoDouble
Документация по MQL5: Получение рыночной информации / SymbolInfoDouble
  • www.mql5.com
2. Возвращает true или false в зависимости от успешности выполнения функции.  В случае успеха значение свойства помещается в приемную переменную, передаваемую по ссылке последним параметром. Если функция используется для получения информации о последнем тике, то лучше использовать SymbolInfoTick(). Вполне возможно, что по данному символу с...
 
Vladimir Karputov:

So, for future reference:

1.SymbolInfoDouble

If this function is used to get information about the last tick, it is better to useSymbolInfoTick(). It's quite possible that there hasn't been any quote for this symbol since the time the terminal connected to the trading account. In this case, the requested value will be undefined.

2. It is better to take the spread as a difference between Ask and Bid.

3. Level of freeze: look for the maximum valueout of three (SYMBOL_TRADE_FREEZE_LEVEL, SYMBOL_TRADE_STOPS_LEVEL and calculated spread) and multiply by three and you will be happy.

Point 3 was deduced in practice when working with KodoBase (and the validator in both KodoBase and Market is the same).

Thank you very much! I will make some changes now and try it.

 
Mikhail Sergeev:

Thank you very much! I'll make the changes now and give it a try.

Yes, the result will be interesting.

 
Vladimir Karputov:

Yes, the result will be interesting.

Problem solved! It turned out to be very simple, in order to delete an order it is necessary to fill in:request.symbol

I haven't found any structured information on what data should be passed to request depending on trade type. And I used examplehttps://www.mql5.com/ru/docs/constants/tradingconstants/enum_trade_request_actions.

It's not there.


I checked many variants with freezing. In my case single size was enough.

Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Типы торговых операций
Документация по MQL5: Константы, перечисления и структуры / Торговые константы / Типы торговых операций
  • www.mql5.com
Торговля осуществляется посредством отправки с помощью функции OrderSend() приказов на открытие позиций, а также приказов на установку, модификацию и удаление отложенных ордеров. Каждый торговый приказ содержит указание на тип запрашиваемой торговой операции. Торговые операции описаны в перечислении ENUM_TRADE_REQUEST_ACTIONS...
 
Mikhail Sergeev:

Problem solved! It turned out to be very simple, in order to delete an order it is necessary to fill inrequest.symbol.

I haven't found any structured information about what data should be passed to request depending on the type of trade operation. And I used example https://www.mql5.com/ru/docs/constants/tradingconstants/enum_trade_request_actions.

It's not there.


I checked many variants with freezing. In my case, single size was enough.

Why do you need such complications? Use the trade class CTrade.

 
Vladimir Karputov:

Why go to all that trouble? Use the CTrade trading class.

Unfortunately this has been around since MT4. It was easier to adapt it.


I don't know about CTrade, but it seems that everywhere where you have to specify a symbol, it is present in parameters passed to the method. And it's not present in method OrderDelete(const ulong ticket), so it won't work. We should fill in the request.symbol somewhere beforehand.

 
Mikhail Sergeev:

Unfortunately, this has been around since MT4. It was easier to adapt.


About CTrade - I didn't understand it, but it seems that everywhere where you need to specify a symbol, it is in the parameters passed to the method. And it's not present in method OrderDelete(const ulong ticket), so it won't work. We have to fill in the request.symbol somewhere.

What won't work? This is a trade class: it sets, modifies and deletes REMOTE ORDERS, and opens, modifies and closes POISONS.

Absolutely everything works. And everything is written in one line by any trade command.


CTrade

Документация по MQL5: Стандартная библиотека / Торговые классы / CTrade
Документация по MQL5: Стандартная библиотека / Торговые классы / CTrade
  • www.mql5.com
Стандартная библиотека / Торговые классы / CTrade - справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Vladimir Karputov:

What won't work then? It's a trading class: sets, modifies and deletes REMOTE ORDERS, opens, modifies and closes POISONS.

Absolutely everything works. And everything is written in one line by any trade command.


CTrade

//+------------------------------------------------------------------+
//| Delete specified pending order                                   |
//+------------------------------------------------------------------+
bool CTrade::OrderDelete(const ulong ticket)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- clean
   ClearStructures();
//--- setting request
   m_request.action    =TRADE_ACTION_REMOVE;
   m_request.magic     =m_magic;
   m_request.order     =ticket;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }

So I just don't understand at what point m_request.symbol is filled

Anyway, problem solved. Thanks again so much for your help!

 
Mikhail Sergeev:

So I just don't understand at what point m_request.symbol is filled in

Anyway, problem solved. Thanks again so much for your help!

Take a debugger throughCTrade and you'll see where the symbol went :)

Reason: