将Windows本地时间与MT5服务器同步 - 页 7 1234567891011121314...17 新评论 fxsaber 2017.01.20 17:05 #61 prostotrader:2017.01.13 10:00:03.979 Trades 'xxxxx': failed sell limit 1.00 ED-6.17 at 1.0813 [Market closed]经纪人的回应2017.01.13 09:59:58.100 * reject (Market closed) for '*' (sell limit 1.00 ED-6.17 at 1.0813)(1.0641 / 1.0814 / 1.0695)显然,你想在本地日志和交换日志中看到相同的时间。现在是时候让开发人员不仅将事件的本地时间,而且将事件的服务器时间写入日志了。那么就不需要同步了。然而,你发送了一个限制,不是本地时间,而是服务器时间。而服务器时间已经设置为上午10点,好像是开放时间。因此,服务器时间没有与交易所时间同步。 Sergey Chalyshev 2017.01.20 17:07 #62 prostotrader:只不过,今天10:00之后(同步是在盘前)。当地时间与市场观察的时间相差7秒。:( 试试我的代码,加入了同步后的自我清算,我会把它放在kodobase里,这样就不会丢失。 prostotrader 2017.01.20 17:12 #63 Sergey Chalyshev: 一个新的报价来了,市场发生了变化--这些是不同的事件。如果一个高于或低于卖出价或买入价的出价被添加(删除),OnBookEvent()事件被接收,但它不是一个新的报价,它不会进入tick历史,因此最后已知的服务器时间不会改变。我不知道还能怎么解释,你在开玩笑吗?))天啊,对了,我弄错了,这句话可能不是最好的!那么我应该使用SymbolInfoTick()。谢谢你,Sergei!添加MqlTick curr_tick; if(SymbolInfoTick(symbol, curr_tick)) //if(CopyTicks(symbol,curr_tick,COPY_TICKS_INFO,0,1)==1) Sergey Chalyshev 2017.01.20 17:12 #64 fxsaber:显然,你想在本地日志和交换日志中看到相同的时间。现在是开发人员不仅要把本地时间,而且要把服务器时间写入日志的时候了。那么就不需要同步了。然而,你发送了一个限制,不是本地时间,而是服务器时间。而服务器时间已经是,仿佛是10点。因此,服务器时间没有与交易所时间同步。时间的同步不会使你 免于[市场关闭], 交易所可以晚一点开始交易,在交易时间暂停交易。你必须在这里采取不同的方法。 prostotrader 2017.01.20 17:15 #65 fxsaber:显然,你想在本地日志和交换日志中看到相同的时间。现在是开发人员不仅要把本地时间,而且要把服务器时间写入日志的时候了。那么就不需要同步了。然而,你发送了一个限制,不是本地时间,而是服务器时间。而服务器时间已经是,仿佛是10点。因此,服务器时间没有与交易所时间同步。那我怎么才能得到服务器的时间呢?我像这样检查服务器时间//+------------------------------------------------------------------+//| 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); }和TimeTradeServer()给出当地时间,而TimeCurrent()可能有 "旧 "时间 :( Synchronise Windows local time Market closed 市场关闭 Sergey Chalyshev 2017.01.20 17:32 #66 prostotrader:但是我的方法和你的方法的区别是巨大的。在我的例子中,使用一个低流动性工具的EA(例如UUAH),你可以添加所有的期货眼镜和它可以保证在市场前期获得一个刻度,而不必担心终端中其他专家顾问的工作。也就是说,所有新的报价将 "进入 "一个单独的EA。由以下人员添加它将只 "处理 "同步问题,不会干扰其他任何人的工作。此外,我们还可以将其他符号的ticks接收到一个单独的EA中。 这必须通过自定义事件来完成。 但我认为这是不必要的,至少,我不需要它。 prostotrader 2017.01.20 17:41 #67 Sergey Chalyshev: 也可以在一个单独的EA中接收来自其他工具的ticks,这应该通过自定义事件完成。 但我认为这是不必要的,至少,我不需要它。而你应该试试我的(它没有被清算)。每天交易前的同步化//+------------------------------------------------------------------+//| 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"; //Brentinput 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; } }//+------------------------------------------------------------------+ Synchronise Windows local time 市场关闭 new mql4 providing millisecond fxsaber 2017.01.20 18:12 #68 prostotrader:试试我的(未被淘汰)。 同样的代码可以简洁许多倍。 prostotrader 2017.01.20 18:17 #69 fxsaber: 同样的代码可以简洁许多倍。当然可以,每个人都有不同的能力和实力。看到你的很有意思。 prostotrader 2017.01.20 21:11 #70 在演示中运行这段代码MqlTick cur_tick, ct_tick[]; 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); } } }并对这一结果感到有些疑惑。2017.01.21 00:07:41.444 Time_sync_forts (ED-3.17,M1) SymbolInfoTick symbiol = GOLD-3.17 time = 2017.01.20 22:14:48.02017.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.7742017.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.7742017.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.7742017.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.3952017.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.4522017.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.4522017.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.2902017.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.7042017.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.7042017.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.3862017.01.21 00:08:28.961 Time_sync_forts (ED-3.17,M1) debugging terminated 事实证明,CopyTicks()并没有保存最后一个刻度?添加MqlTick cur_tick, ct_tick[]; 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); } } }结果2017.01.21 00:15:54.670 Time_sync_forts (ED-3.17,M1) SymbolInfoTick symbiol = GOLD-3.17 time = 2017.01.20 22:14:48.02017.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.6582017.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.5122017.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.5122017.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.2452017.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.2452017.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.5622017.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.1592017.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.6012017.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.8522017.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.303MqlTick cur_tick, ct_tick[]; 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); } } }结果2017.01.21 00:17:55.966 Time_sync_forts (ED-3.17,M1) SymbolInfoTick symbiol = GOLD-3.17 time = 2017.01.20 22:14:48.02017.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.7742017.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.7742017.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.7742017.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.3952017.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.4522017.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.4522017.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.2902017.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.7042017.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.7042017.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谁能澄清一下?添加在RTS上也是如此。2017.01.21 00:20:42.464 Time_sync_forts (ED-3.17,M1) debugging terminated2017.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.02017.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.6192017.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.6192017.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.6192017.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.2022017.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.7542017.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.1532017.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.5482017.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.5122017.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.5122017.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 由以下人员添加而在继电器上也是如此。2017.01.21 00:44:21.893 Time_sync_forts (ALRS-3.17,H1) SymbolInfoTick symbiol = Si-3.17 time = 2017.01.20 23:59:56.9592017.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.9042017.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.8672017.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.8892017.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.7312017.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.2962017.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.592017.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.9372017.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.9342017.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.9332017.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.9332017.01.21 00:44:24.151 Time_sync_forts (ALRS-3.17,H1) debugging terminated Synchronise Windows local time BrainSystem: Trading System Development PREDICT time period 1234567891011121314...17 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
经纪人的回应
显然,你想在本地日志和交换日志中看到相同的时间。现在是时候让开发人员不仅将事件的本地时间,而且将事件的服务器时间写入日志了。那么就不需要同步了。
然而,你发送了一个限制,不是本地时间,而是服务器时间。而服务器时间已经设置为上午10点,好像是开放时间。因此,服务器时间没有与交易所时间同步。
只不过,今天10:00之后(同步是在盘前)。
当地时间与市场观察的时间相差7秒。:(
一个新的报价来了,市场发生了变化--这些是不同的事件。如果一个高于或低于卖出价或买入价的出价被添加(删除),OnBookEvent()事件被接收,但它不是一个新的报价,它不会进入tick历史,因此最后已知的服务器时间不会改变。
我不知道还能怎么解释,你在开玩笑吗?))
天啊,对了,我弄错了,这句话可能不是最好的!
那么我应该使用SymbolInfoTick()。
谢谢你,Sergei!
添加
if(SymbolInfoTick(symbol, curr_tick))
//if(CopyTicks(symbol,curr_tick,COPY_TICKS_INFO,0,1)==1)
显然,你想在本地日志和交换日志中看到相同的时间。现在是开发人员不仅要把本地时间,而且要把服务器时间写入日志的时候了。那么就不需要同步了。
然而,你发送了一个限制,不是本地时间,而是服务器时间。而服务器时间已经是,仿佛是10点。因此,服务器时间没有与交易所时间同步。
时间的同步不会使你 免于[市场关闭], 交易所可以晚一点开始交易,在交易时间暂停交易。
你必须在这里采取不同的方法。
显然,你想在本地日志和交换日志中看到相同的时间。现在是开发人员不仅要把本地时间,而且要把服务器时间写入日志的时候了。那么就不需要同步了。
然而,你发送了一个限制,不是本地时间,而是服务器时间。而服务器时间已经是,仿佛是10点。因此,服务器时间没有与交易所时间同步。
那我怎么才能得到服务器的时间呢?
我像这样检查服务器时间
//| 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);
}
和TimeTradeServer()
给出当地时间,而TimeCurrent()可能有 "旧 "时间 :(
但是我的方法和你的方法的区别是巨大的。
在我的例子中,使用一个低流动性工具的EA(例如UUAH),你可以添加所有的期货眼镜和
它可以保证在市场前期获得一个刻度,而不必担心终端中其他专家顾问的工作。
也就是说,所有新的报价将 "进入 "一个单独的EA。
由以下人员添加
它将只 "处理 "同步问题,不会干扰其他任何人的工作。
此外,我们还可以将其他符号的ticks接收到一个单独的EA中。 这必须通过自定义事件来完成。
但我认为这是不必要的,至少,我不需要它。
也可以在一个单独的EA中接收来自其他工具的ticks,这应该通过自定义事件完成。
但我认为这是不必要的,至少,我不需要它。
而你应该试试我的(它没有被清算)。
每天交易前的同步化
//| 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;
}
}
//+------------------------------------------------------------------+
试试我的(未被淘汰)。
同样的代码可以简洁许多倍。
当然可以,每个人都有不同的能力和实力。
看到你的很有意思。
在演示中运行这段代码
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);
}
}
}
并对这一结果感到有些疑惑。
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
事实证明,CopyTicks()并没有保存最后一个刻度?
添加
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);
}
}
}
结果
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);
}
}
}
结果
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
谁能澄清一下?
添加
在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
由以下人员添加
而在继电器上也是如此。
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