Ti stai perdendo delle opportunità di trading:
- App di trading gratuite
- Oltre 8.000 segnali per il copy trading
- Notizie economiche per esplorare i mercati finanziari
Registrazione
Accedi
Accetti la politica del sito e le condizioni d’uso
Se non hai un account, registrati
Risposta del broker
A quanto pare, volete vedere lo stesso tempo nel log locale e nel log di scambio. È giunto il momento per gli sviluppatori di scrivere nel log non solo l'ora locale ma anche quella del server dell'evento. Allora la sincronizzazione non è necessaria.
Tuttavia, avete inviato un limite, non un'ora locale, ma l'ora del server. E l'ora del server era già, come se fossero le 10:00. Quindi l'ora del server non era sincronizzata con l'ora di scambio.
Solo, oggi, dopo le 10:00 (la sincronizzazione era in pre-mercato)
l'ora locale differisce da quella del Market Watch di 7 secondi. :(
È arrivata una nuova quotazione e il mercato è cambiato - sono eventi diversi. Se un'offerta superiore o inferiore alla domanda o all'offerta viene aggiunta (rimossa), l'evento OnBookEvent() viene ricevuto, ma non è una nuova quotazione e non entra nella cronologia dei tick, quindi l'ultimo orario noto del server non cambia.
Non so come altro spiegarlo, stai scherzando? ))
Accidenti, è vero, ho fatto un casino, la citazione potrebbe non essere la migliore!
Allora dovrei usareSymbolInfoTick()
Grazie, Sergei!
Aggiunto
if(SymbolInfoTick(symbol, curr_tick))
//if(CopyTicks(symbol,curr_tick,COPY_TICKS_INFO,0,1)==1)
A quanto pare, volete vedere lo stesso tempo nel log locale e nel log di scambio. È giunto il momento per gli sviluppatori di scrivere nel log non solo il tempo locale ma anche quello del server. Allora la sincronizzazione non è necessaria.
Tuttavia, avete inviato un limite, non un'ora locale, ma l'ora del server. E l'ora del server era già, come se fossero le 10:00. Quindi, l'ora del server non era sincronizzata con l'ora di scambio.
La sincronizzazione del tempo non ti salverà da[Mercato chiuso], lo scambio può iniziare il trading più tardi e sospendere il trading all'ora del trading.
Qui bisogna avere un approccio diverso.
A quanto pare, volete vedere lo stesso tempo nel log locale e nel log di scambio. È giunto il momento per gli sviluppatori di scrivere nel log non solo il tempo locale ma anche quello del server. Allora la sincronizzazione non è necessaria.
Tuttavia, avete inviato un limite, non un'ora locale, ma l'ora del server. E l'ora del server era già, come se fossero le 10:00. Quindi, l'ora del server non era sincronizzata con l'ora dello scambio.
E come posso ottenere l'ora del server?
Controllo il tempo del server in questo modo
//| Expert Check traiding time function |
//+------------------------------------------------------------------+
bool CheckTradingTime(MqlDateTime &tick_time)
{
datetime lk_time = TimeTradeServer(tick_time);
if ( ( tick_time.day_of_week == int(FirstDay)) ||
( tick_time.day_of_week == int(SecondDay)))//выходные
{
return(false);
}
#ifdef DEBUG
if ((tick_time.hour >= 0) && (tick_time.hour < 6)) // DEBUG 6-00
{
return(false);
}
#else
if ((tick_time.hour >= 0) && (tick_time.hour < 10))
{
return(false);
}
#endif
// 13 * 3600 + 59 * 60 + 30 = 50370 - 13:59:30
// 14 * 3600 = 50400 - 14:00:00
// 14 * 3600 + 30 = 50430 - 14:00:30
// 14 * 3600 + 60 = 50460 - 14:01:00
// 18 * 3600 + 44 * 60 + 30 = 67470 - 18:44:30
// 18 * 3600 + 45 * 60 = 67500 - 18:45:00
// 18 * 3600 + 45 * 60 + 30 = 67530 - 18:45:30
// 18 * 3600 + 46 * 60 = 67560 - 18:46:00
// 19 * 3600 = 68400 - 19:00:00
// 19 * 3600 + 60 = 68460 - 19:01:00
// 23 * 3600 + 49 * 60 + 30 = 85770 - 23:49:30
// 23 * 3600 + 50 * 60 = 85800 - 23:50:00
// 23 * 3600 + 50 * 60 + 30 = 85830 - 23:50:30
// 23 * 3600 + 51 * 60 = 85860 - 23:51:00
//---
ulong trade_time = tick_time.hour * 3600 + tick_time.min * 60 + tick_time.sec;
//--- //10:00:02
if(((trade_time >= time_st_mon) && (trade_time < 50370)) ||
((trade_time >= time_st_day) && (trade_time < 67470)) ||
((trade_time >= time_st_evn) && (trade_time < 85770)))
{
return(true);
}
return(false);
}
ETimeTradeServer()
dà l'ora locale, e TimeCurrent() può avere l'ora "vecchia" :(
Ma la differenza tra il mio approccio e il tuo è enorme.
Nel mio caso, usando un EA per uno strumento illiquido (per esempio UUAH) si possono aggiungere TUTTI gli stack di TUTTI i futures e
è GARANTITO ottenere un tick nel premercato, senza preoccuparsi del lavoro di altri Expert Advisors nel terminale.
Cioè tutte le nuove citazioni "andranno" in un EA separato.
Aggiunto da
Si "occuperà" solo della sincronizzazione e non interferirà con il lavoro di nessun altro.
Inoltre, possiamo ricevere tick da altri simboli in un EA separato. Questo deve essere fatto attraverso eventi personalizzati.
Ma penso che non sia necessario, almeno io non ne ho bisogno.
È anche possibile ricevere tick da altri strumenti in un EA separato, questo dovrebbe essere fatto attraverso eventi personalizzati.
Ma penso che non sia necessario, almeno io non ne ho bisogno.
E dovresti provare il mio (non è liquidato).
Sincronizzazione prima del trading ogni giorno
//| Time_sync_forts.mq5 |
//| Copyright 2017 prostotrader |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017 prostotrader"
#property link "https://www.mql5.com"
#property version "1.01"
//---
struct _SYSTEMTIME
{
ushort wYear;
ushort wMonth;
ushort wDayOfWeek;
ushort wDay;
ushort wHour;
ushort wMinute;
ushort wSecond;
ushort wMilliseconds;
};
_SYSTEMTIME loc_time;
#import "kernel32.dll"
void GetLocalTime(_SYSTEMTIME &sys_time);
bool SetLocalTime(_SYSTEMTIME &sys_time);
#import
//---
bool is_sync;
string symb_rts;
string symb_si;
string symb_gold;
string symb_br;
string symb_gazr;
string symb_sbrf;
//
input string BrInstr = "BR-2.17"; //Brent
input ENUM_DAY_OF_WEEK FirstDay = SATURDAY; //Первый выходной
input ENUM_DAY_OF_WEEK SecondDay = SUNDAY; //Второй выходной
//+------------------------------------------------------------------+
//| Expert set second symbol function |
//+------------------------------------------------------------------+
string SetSecSymbol(const string a_symbol,const string prefix)
{
int str_tire=0;
ushort let_symbol;
int str_size=StringLen(a_symbol);
for(int i=0; i<str_size; i++)
{
let_symbol=StringGetCharacter(a_symbol,i);
if(let_symbol=='-')
{
str_tire=i;
break;
}
}
if(str_tire>0)
{
return(prefix + StringSubstr(a_symbol, str_tire, str_size - str_tire));
}
return("");
}
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
is_sync=false;
MarketBookAdd(Symbol());
//---
symb_rts=SetSecSymbol(Symbol(),"RTS");
if(!SymbolSelect(symb_rts,true))
{
MessageBox(symb_rts+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
else MarketBookAdd(symb_rts);
//---
symb_si=SetSecSymbol(Symbol(),"Si");
if(!SymbolSelect(symb_si,true))
{
MessageBox(symb_si+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
else MarketBookAdd(symb_si);
//---
symb_gold=SetSecSymbol(Symbol(),"GOLD");
if(!SymbolSelect(symb_gold,true))
{
MessageBox(symb_gold+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
else MarketBookAdd(symb_gold);
//---
symb_gazr=SetSecSymbol(Symbol(),"GAZR");
if(!SymbolSelect(symb_gazr,true))
{
MessageBox(symb_gazr+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
else MarketBookAdd(symb_gazr);
//---
symb_sbrf=SetSecSymbol(Symbol(),"SBRF");
if(!SymbolSelect(symb_sbrf,true))
{
MessageBox(symb_sbrf+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
else MarketBookAdd(symb_sbrf);
//---
symb_br=BrInstr;
if(!SymbolSelect(symb_br,true))
{
MessageBox(symb_br+" not found in the Market watch!","Error",MB_OK|MB_ICONERROR);
return(INIT_FAILED);
}
else MarketBookAdd(symb_br);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
MarketBookRelease(Symbol());
MarketBookRelease(symb_rts);
MarketBookRelease(symb_br);
MarketBookRelease(symb_si);
MarketBookRelease(symb_gold);
MarketBookRelease(symb_gazr);
MarketBookRelease(symb_sbrf);
}
//+------------------------------------------------------------------+
//| Expert Convert To Time function |
//+------------------------------------------------------------------+
bool ConvertToTime(const long n_value,_SYSTEMTIME &a_time)
{
a_time.wMilliseconds=ushort(n_value%1000);
ulong new_time=ulong(double(n_value)/1000);
MqlDateTime cur_time = {0};
TimeToStruct(datetime(new_time),cur_time);
if(cur_time.year>0)
{
a_time.wDay=ushort(cur_time.day);
a_time.wDayOfWeek=ushort(cur_time.day_of_week);
a_time.wHour=ushort(cur_time.hour);
a_time.wMinute= ushort(cur_time.min);
a_time.wMonth = ushort(cur_time.mon);
a_time.wSecond= ushort(cur_time.sec);
a_time.wYear=ushort(cur_time.year);
return(true);
}
return(false);
}
//+------------------------------------------------------------------+
//| Expert On book event function |
//+------------------------------------------------------------------+
void OnBookEvent(const string &symbol)
{
loc_time.wYear=0;
GetLocalTime(loc_time);
if(loc_time.wYear>0)
{
if((int(loc_time.wDayOfWeek) == int(FirstDay)) ||
(int(loc_time.wDayOfWeek) == int(SecondDay))) return;
if((loc_time.wHour==9) && (loc_time.wMinute>=50) && (loc_time.wMinute<=59))
{
MqlTick curr_tick;
if(SymbolInfoTick(symbol, curr_tick))
//if(CopyTicks(symbol,curr_tick,COPY_TICKS_INFO,0,1)==1)
{
MqlDateTime sv_time;
TimeToStruct(curr_tick.time,sv_time);
if(!is_sync)
{
if((loc_time.wDayOfWeek==ushort(sv_time.day_of_week)) &&
(loc_time.wHour==ushort(sv_time.hour)))
{
long last_ping=long(NormalizeDouble((double(TerminalInfoInteger(TERMINAL_PING_LAST))/1000)/2,0));
long mls_time=long(curr_tick.time_msc%1000);
if((mls_time+last_ping)>999)
{
mls_time=long(curr_tick.time_msc)+last_ping;
if(!ConvertToTime(mls_time, loc_time)) return;
}
else
{
loc_time.wMinute = ushort(sv_time.min);
loc_time.wSecond = ushort(sv_time.sec);
loc_time.wMilliseconds=ushort(mls_time);
}
if(SetLocalTime(loc_time))
{
is_sync=true;
Print("Local time sync is done. Symbol = ", symbol, " Sync min = ", loc_time.wMinute,
" Sync sec = ", loc_time.wSecond, " Sync ms = ", loc_time.wMilliseconds);
}
}
}
}
}
else is_sync=false;
}
}
//+------------------------------------------------------------------+
Prova il mio (non eliminato)
Lo stesso codice potrebbe essere molto più succinto.
Certo che può, ognuno ha diverse abilità e capacità.
È interessante vedere il tuo.
Ha eseguito questo codice nella demo
if(SymbolInfoTick(symb_gold, cur_tick))
{
int result = CopyTicks(symb_gold, ct_tick, COPY_TICKS_INFO, 0, 10);
if(result>0)
{
Print("SymbolInfoTick symbiol = ", symb_gold, " time = ", cur_tick.time, ".", cur_tick.time_msc%1000);
for(int i = result-1; i >=0; i--)
{
Print("CopyTicks symbol = ", symb_gold, " time ", string(i), " = ", ct_tick[i].time, ".", ct_tick[i].time_msc%1000);
}
}
}
ed era un po' perplesso dal risultato.
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 9 = 2017.01.20 22:13:36.774
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 8 = 2017.01.20 22:13:36.774
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 7 = 2017.01.20 22:13:36.774
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 6 = 2017.01.20 22:11:14.395
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 5 = 2017.01.20 22:09:47.452
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 4 = 2017.01.20 22:09:47.452
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 3 = 2017.01.20 22:08:34.290
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 2 = 2017.01.20 22:07:29.704
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 1 = 2017.01.20 22:07:29.704
2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 0 = 2017.01.20 22:06:35.386
2017.01.21 00:08:28.961 Time_sync_forts (ED-3.17,M1) debugging terminated
Risulta che CopyTicks() non salva l'ultimo tick?
Aggiunto
if(SymbolInfoTick(symb_gold, cur_tick))
{
int result = CopyTicks(symb_gold, ct_tick, COPY_TICKS_TRADE, 0, 10);
if(result>0)
{
Print("SymbolInfoTick symbiol = ", symb_gold, " time = ", cur_tick.time, ".", cur_tick.time_msc%1000);
for(int i = result-1; i >=0; i--)
{
Print("CopyTicks symbol = ", symb_gold, " time ", string(i), " = ", ct_tick[i].time, ".", ct_tick[i].time_msc%1000);
}
}
}
Risultato
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 9 = 2017.01.20 21:59:59.658
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 8 = 2017.01.20 21:57:54.512
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 7 = 2017.01.20 21:57:54.512
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 6 = 2017.01.20 21:57:54.245
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 5 = 2017.01.20 21:57:54.245
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 4 = 2017.01.20 21:57:00.562
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 3 = 2017.01.20 21:56:45.159
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 2 = 2017.01.20 21:56:13.601
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 1 = 2017.01.20 21:55:16.852
2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 0 = 2017.01.20 21:54:16.303
if(SymbolInfoTick(symb_gold, cur_tick))
{
int result = CopyTicks(symb_gold, ct_tick, COPY_TICKS_ALL, 0, 10);
if(result>0)
{
Print("SymbolInfoTick symbiol = ", symb_gold, " time = ", cur_tick.time, ".", cur_tick.time_msc%1000);
for(int i = result-1; i >=0; i--)
{
Print("CopyTicks symbol = ", symb_gold, " time ", string(i), " = ", ct_tick[i].time, ".", ct_tick[i].time_msc%1000);
}
}
}
Risultato
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 9 = 2017.01.20 22:13:36.774
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 8 = 2017.01.20 22:13:36.774
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 7 = 2017.01.20 22:13:36.774
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 6 = 2017.01.20 22:11:14.395
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 5 = 2017.01.20 22:09:47.452
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 4 = 2017.01.20 22:09:47.452
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 3 = 2017.01.20 22:08:34.290
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 2 = 2017.01.20 22:07:29.704
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 1 = 2017.01.20 22:07:29.704
2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = GOLD-3.17 time 0 = 2017.01.20 22:06:35.386
Qualcuno può chiarire?
Aggiunto
Lo stesso su RTS.
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) SymbolInfoTick symbiol = RTS-3.17 time = 2017.01.20 22:14:55.0
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 9 = 2017.01.20 22:12:41.619
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 8 = 2017.01.20 22:12:41.619
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 7 = 2017.01.20 22:12:41.619
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 6 = 2017.01.20 22:12:02.202
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 5 = 2017.01.20 22:11:00.754
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 4 = 2017.01.20 22:08:35.153
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 3 = 2017.01.20 22:08:23.548
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 2 = 2017.01.20 22:07:28.512
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 1 = 2017.01.20 22:07:28.512
2017.01.21 00:21:11.589 Time_sync_forts (ED-3.17,M1) CopyTicks symbol = RTS-3.17 time 0 = 2017.01.20 22:07:28.512
Aggiunto da
Ed è lo stesso per il relè.
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 9 = 2017.01.20 23:54:35.904
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 8 = 2017.01.20 23:53:04.867
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 7 = 2017.01.20 23:51:55.889
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 6 = 2017.01.20 23:50:55.731
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 5 = 2017.01.20 23:49:59.296
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 4 = 2017.01.20 23:49:59.59
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 3 = 2017.01.20 23:49:58.937
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 2 = 2017.01.20 23:49:58.934
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 1 = 2017.01.20 23:49:58.933
2017.01.21 00:44:21.895 Time_sync_forts (ALRS-3.17,H1) CopyTicks symbol = Si-3.17 time 0 = 2017.01.20 23:49:58.933
2017.01.21 00:44:24.151 Time_sync_forts (ALRS-3.17,H1) debugging terminated