Características del lenguaje mql5, sutilezas y técnicas - página 79

 
Alain Verleyen:

Me gustaría obtener la hora del servidor de acuerdo a GMT.

Esto es lo que se obtiene al ejecutar el script. Hay una salida especial de dos valores: TimeGMT y TimeServerGMT, para que pueda comprobar si coinciden.

Si son iguales, no tienes ningún error.

 
fxsaber:

Se obtiene esto cuando se ejecuta el script. Allí se emiten especialmente dos valores: TimeGMT y TimeServerGMT, para que pueda comprobar que coinciden.

Si coinciden, no hay error, de lo contrario hay un error.

Lo tengo.
 

Foro sobre comercio, sistemas de comercio automatizados y pruebas de estrategias

Bibliotecas: TypeToBytes

fxsaber, 2018.03.31 09:24

// Кроссплатформенный пример передачи произвольных данных через пользовательское событие

#include <fxsaber\HistoryTicks\Data_String.mqh> // https://www.mql5.com/ru/code/20298

// Печать произвольных данных
template <typename T>
bool MyPrint( const T &Value )
{
  T Array[1];
  
  Array[0] = Value;
  
  ArrayPrint(Array, _Digits, NULL, 0, WHOLE_ARRAY, ARRAYPRINT_HEADER | ARRAYPRINT_ALIGN);
  
  return(true);
}

void OnChartEvent( const int id, const long &lparam, const double&, const string &sparam )
{
  // Распечатали полученные данные
  if ((id == CHARTEVENT_CUSTOM) &&
      (lparam ?  MyPrint(DATA_STRING::FromString<MqlDateTime>(sparam)) // Получили MqlDateTime
              : !MyPrint(DATA_STRING::FromString<MqlTick>(sparam))))   // Получили MqlTick
    ExpertRemove(); // Вышли из примера
}

void OnInit()
{
  MqlTick Tick;  
  MqlDateTime DateTime;
  
  // Заполнили значения
  SymbolInfoTick(_Symbol, Tick);  
  TimeCurrent(DateTime);

  // Передали
  EventChartCustom(0, 0, 0, 0, DATA_STRING::ToString(Tick));     // Передали MqlTick
  EventChartCustom(0, 0, 1, 0, DATA_STRING::ToString(DateTime)); // Передали MqlDateTime
}
 
fxsaber:

Sparam tiene un límite de longitud. ¿Lo has tenido en cuenta?

 
Andrey Barinov:

Sparam tiene un límite de longitud.

Sí, 128 bytes.

const bool Init = EventChartCustom(0, 0, 0, 0, NULL);

void OnChartEvent( const int id, const long&, const double&, const string &sparam )
{
  static int PrevLength = -1;
  
  if (id == CHARTEVENT_CUSTOM)
  {
    const int Length = StringLen(sparam);

    bool Res = (Length != PrevLength);
    
    if (Res)
    {
      string Str;
            
      StringInit(Str, Length + 1, 1);
      
      Res = EventChartCustom(0, 0, 0, 0, Str);
    }
    
    if (!Res)
    {
      Print(PrevLength);
      
      ExpertRemove();
    }
      
    PrevLength = Length;      
  }
}

¿Lo has tenido en cuenta?

No, eso es lo que se puede ver en él. El ejemplo de sparam se da como una de las variantes de almacenamiento de cadenas.

Puedes complicar el código (enviarlo en trozos), pero entonces perderás claridad visual.

 
fxsaber:

Me temo que sin un ejemplo concreto, no hay una salida constructiva.

Está dando una imagen como esta:


  Print( "TimeServer: ",TimeGMT()-TimeServerGMTOffset() );
  Print( "TimeServerGMT: ",TimeServerGMT() );
  Print( "TimeCurrent: ",TimeCurrent() );
  Print( "TimeLocal: ",TimeLocal() );
  Print( "TimeGMT: ",TimeGMT() );
  Print( "TimeGMTOffset: ",TimeServerGMTOffset() );
  Print( "" );

Y aquí está el instalador de mt4 con un turno de trabajoGMT+2.

Esperaba verTimeServer=2018.04.01 05:54:26

Archivos adjuntos:
tw4setup.zip  522 kb
 
Vitaly Muzichenko:

Da una imagen como esta:

Porsi acaso, dame el nombre del servidor TradersWay-Demo.

SZZ TradersWay-Demo.

Funciona correctamente.

2018.04.01 08:36:08.858 TimeServerGMT EURUSDi,M1: TimeServerGMT() = 2018.03.30 19:59:59

Puede que no lo tengas.

// Работает для FOREX-символов, когда M1-история доступна за ближайшую неделю
 
fxsaber:

Por si acaso, dame el nombre del servidor de comercio.

ZS TradersWay-Demo.

Funciona correctamente.

Puede que no lo tengas.

Probablemente no. Probablemente no lo tenga en ningún terminal, nunca cambio de marco temporal por debajo de M15

Vale, lo investigaré un poco más.
 
Vitaly Muzichenko:

Probablemente no. Probablemente no lo tenga en ningún terminal, nunca cambio de plazos por debajo de M15

Hazlo así

datetime GetBarTime( const datetime time, const bool NextBar = false, string Symb = NULL, const ENUM_TIMEFRAMES TimeFrame = PERIOD_M15 )
 
fxsaber:

Haz esto.

Hecho esto, no mostró ninguna mierda. Lo que es confuso es que el desplazamiento debería ser probablemente -720



P.D. De nuevo, sé que el turno +2 horas está escrito en la página web, pero el robot no lo sabe.

Si ejecuta el Asesor Experto en un gráfico como este, es poco probable que obtenga el resultado de salida requerido: "Aprende el servidor de tiempo actual TimeServer()" No lo he entendido bien, tal vez estoy haciendo algo mal.

Tal vez los desarrolladores deberían implementar la función en el terminal.