Domande di OrderSend() - pagina 3

 
 komposter:

La contabilità degli ordini in MT5 è tutta una scienza:Gestire gli eventi di compravendita nell'Expert Advisor usando la funzione OnTrade()

Nessuna pausa vi salverà dalla riapertura, può sempre verificarsi una situazione in cui l'ordine impiegherà 1 secondo in più per essere eseguito.

ps: E non dimenticare la magia.

Il facilitatore?

Nessuna quantità di scienza vi salverà dalle macchinazioni della metanfetamina globale

di meta-fobia globale.

Provando

 
her.human:
Pensare prima di postare è considerato un buon stile.
 

Purtroppo, MT5 ha molte più trappole di MT4.

Il problema dell'aggiornamento ritardato dei dati dopo l'esecuzione riuscita diOrderSend() è risolto nell'ultima riga dell'esempio seguente:

MqlTradeRequest request;
MqlTradeResult result;
...
OrderSend(request,result);
...
Ticket=false;
Error==result.retcode;
if(Error==10008 || Error==10009){Ticket=true;}
...
if(Ticket==true){while(!HistoryDealSelect(result.deal)){RefreshRates();Sleep(1);}}   

Funzione di aggiornamento:

bool RefreshRates()
  {
   MqlTick tick;
   return(SymbolInfoTick(Symbol(),tick));
  }
 
sergey1294:

Ecco qui, dovrebbe funzionare.


//+------------------------------------------------------------------+
//|                                                         Deal.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2012, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(1);

//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---

   if(zOrderSend(_Symbol,0.1,ORDER_TYPE_BUY)==10009) // 10009 TRADE_RETCODE_DONE Заявка выполнена
     {
      Alert("Купили!");
     }
   else Alert("Не купили....");
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---

  }
//+------------------------------------------------------------------+
uint zOrderSend(string zSymbol,double zVolume,ENUM_ORDER_TYPE zORDER_TYPE)
  {
   MqlTradeRequest      request;
   MqlTradeCheckResult  ch_result;
   MqlTradeResult       result;

// обнулим структуру запроса перед заполнением
   ZeroMemory(request);

   Alert("*****************",zSymbol," ",zVolume," ",zORDER_TYPE);
// заполняем структуру
   request.action=TRADE_ACTION_DEAL;
   request.type_filling=ORDER_FILLING_AON;
   request.symbol=zSymbol;
   request.type=zORDER_TYPE;
   request.deviation=30;
   request.sl=0.0;
   request.tp=0.0;
   request.volume=zVolume;
   if(zORDER_TYPE==ORDER_TYPE_BUY)request.price=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   if(zORDER_TYPE==ORDER_TYPE_SELL)request.price=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

// выводим на печать заполненную структуру торгового запроса
   Alert("   ENUM_TRADE_REQUEST_ACTIONS    request.action;           // Тип выполняемого действия                                     =",request.action,"=");
   Alert("   ulong                         request.magic;            // Штамп эксперта (идентификатор magic number)                   =", request.magic,         "=" );
   Alert("   ulong                         request.order;            // Тикет ордера                                                  =", request.order,         "=" );
   Alert("   string                        request.symbol;           // Имя торгового инструмента                                     =", request.symbol,        "=" );
   Alert("   double                        request.volume;           // Запрашиваемый объем сделки в лотах                            =", request.volume,        "=" );
   Alert("   double                        request.price;            // Цена                                                          =", request.price,         "=" );
   Alert("   double                        request.stoplimit;        // Уровень StopLimit ордера                                      =", request.stoplimit,     "=" );
   Alert("   double                        request.sl;               // Уровень Stop Loss ордера                                      =", request.sl,            "=" );
   Alert("   double                        request.tp;               // Уровень Take Profit ордера                                    =", request.tp,            "=" );
   Alert("   ulong                         request.deviation;        // Максимально приемлемое отклонение от запрашиваемой цены       =", request.deviation,     "=" );
   Alert("   ENUM_ORDER_TYPE               request.type;             // Тип ордера                                                    =", request.type,          "=" );
   Alert("   ENUM_ORDER_TYPE_FILLING       request.type_filling;     // Тип ордера по исполнению                                      =", request.type_filling,  "=" );
   Alert("   ENUM_ORDER_TYPE_TIME          request.type_time;        // Тип ордера по времени действия                                =", request.type_time,     "=" );
   Alert("   datetime                      request.expiration;       // Срок истечения ордера (для ордеров типа ORDER_TIME_SPECIFIED) =", request.expiration,    "=" );
   Alert("   string                        request.comment;          // Комментарий к ордеру                                          =", request.comment,       "=" );

// отправляем структуру запроса на проверку
   if(OrderCheck(request,ch_result)==false)
     {
      Alert("OrderCheck выявил ошибку: "+IntegerToString(ch_result.retcode)+"/"+ch_result.comment);
      return ch_result.retcode;
     }
// отправляем запрос на торговый сервер
   if(OrderSend(request,result)==false)
     {
      Alert("OrderSend возвратил ошибку: "+IntegerToString(result.retcode)+"/"+result.comment);
      return result.retcode;
     }
// выводим на печать структуру ответа сервера
   Alert("Код результата операции сервера: " + IntegerToString(result.retcode));
   Alert("deal Тикет сделки "                + IntegerToString(result.deal));
   Alert("order Тикет ордера "               + IntegerToString(result.order));
   Alert("volume Объем сделки "              + DoubleToString (result.volume));
   Alert("price Цена в сделке "              + DoubleToString (result.price));
   Alert("bid(цены реквоты) "                + DoubleToString (result.bid));
   Alert("ask(цены реквоты) "                + DoubleToString (result.ask));
   Alert("Комментарий: "+result.comment);

   return result.retcode;
  }
//+------------------------------------------------------------------+

In questo grande codice - tutto ha funzionato bene,

ma c'è stato un cambiamento nel linguaggio di programmazione.

mql5 è stato rimosso.

ORDER_FILLING_AON;

E ora la compilazione non funziona in questo posto.

Puoi dirmi come riempire correttamente la struttura ora?

// заполняем структуру
   request.action=TRADE_ACTION_DEAL;
   request.type_filling=ORDER_FILLING_AON;
   request.symbol=zSymbol;
   request.type=zORDER_TYPE;
   request.deviation=30;
   request.sl=0.0;
   request.tp=0.0;
   request.volume=zVolume;
   if(zORDER_TYPE==ORDER_TYPE_BUY)request.price=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   if(zORDER_TYPE==ORDER_TYPE_SELL)request.price=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
 
awkozlov:

In questo meraviglioso codice - tutto ha funzionato bene,

ma c'è stato un cambiamento nel linguaggio di programmazione.

mql5 è stato rimosso

La risposta è qui - https://www.mql5.com/ru/forum/6343/page8#comment_189991. Sì, hanno perso questo punto e non l'hanno annunciato negli annunci per qualche motivo.
 

Grazie mille, Rosh!

Anche se, ho cambiato - per "prendere ciò che è disponibile" come ho un flip aggressivo che è improbabile che accada.

Davvero curioso, quali strumenti intendevano gli sviluppatori con le sigle primarie in russo o la trascrizione importata?

Per curiosità, come erano implicate verbalmente le 2 varianti?

 
awkozlov:

Per curiosità, come sono state implicate verbalmente le 2 opzioni?

  • ORDER_FILLING_AON - Un'operazione può essere eseguita solo nel volume specificato e ad un prezzo che è uguale o migliore di quello specificato nell'ordine. Se un volume sufficiente di offerte per il simbolo dell'ordine non è disponibile sul mercato al momento, l'ordine non sarà eseguito.
  • ORDER_FILLING_CANCEL - Un accordo per eseguire un'operazione al massimo volume disponibile sul mercato entro il volume specificato nell'ordine, e a un prezzo uguale o migliore di quello specificato nell'ordine. In questo caso non vengono effettuati ordini aggiuntivi per il volume mancante.
  •  

    Poiché possiamo avere due politiche di esecuzione per un ordine a mercato, ORDER_FILLING_FOK e ORDER_FILLING_IOC, quanto sarebbe appropriato compilare il campo request.type_filling in una richiesta di compravendita come segue:

    request.type_filling=ORDER_FILLING_FOK | ORDER_FILLING_IOC
    Il compilatore genera solo l'avvertimento: conversione implicita di enum. È sufficiente perché la richiesta venga elaborata correttamente, indipendentemente dalla politica di esecuzione impostata dal broker/dealer?
     
    Yedelkin:
    Il compilatore genera solo l'avvertimento: conversione implicita di enum. È sufficiente perché la richiesta venga elaborata correttamente, indipendentemente dalla politica di esecuzione impostata dal broker/dealer?

    È come "caffè nero e latte": due politiche che si escludono a vicenda. Ecco altri link in inglese:

    Fill Or Kill (FOK) Definition | Investopedia
    Fill Or Kill (FOK) Definition | Investopedia
    • www.investopedia.com
    A type of time-in-force designation used in securities trading that instructs a brokerage to execute a transaction immediately and completely or not at all. This type of order is most likely to be used by active traders and is usually for a large quantity of stock. The order must be filled in its entirety or canceled (killed). The purpose of a...
     
    Yedelkin:

    Poiché possiamo avere due politiche di esecuzione per un ordine a mercato, ORDER_FILLING_FOK e ORDER_FILLING_IOC,

    Questo significa che potete scegliere tra le due opzioni.
    Motivazione: