13611347809 发表于 2016-10-15 23:36:34

用毫米计时器代替TICK函数运算

编写EA,当行情剧烈变化时,报价更新极快,此时若EA程序运行时间大于tick间隔时间,会出现下单、平仓是提示“市价已变”问题。对于这个问题,如果采用调用MT4提供的毫米计时器中断函数,运行核心策略,TICK函数进行辅助运算,并使用RefreshRate()刷新数据,对于解决“市价已变”问题,追踪判断最新的价格数据,会有加大的帮助。

luckhare 发表于 2016-10-17 08:56:08

好方法,有没有例子程序。想编个mt4里面的万年历。

13611347809 发表于 2016-10-17 09:02:50

luckhare 发表于 2016-10-17 08:56 static/image/common/back.gif
好方法,有没有例子程序。想编个mt4里面的万年历。

正在调试试验追踪策略,调用毫秒计时器是其中的一个功能。只提个思路,还不成熟,见谅。

柒侠伍义 发表于 2016-10-17 10:05:34

1 秒是肯定可以了,1毫秒?........
MT4不提供方法,应该没有办法办到

13611347809 发表于 2016-10-17 10:27:10

柒侠伍义 发表于 2016-10-17 10:05 static/image/common/back.gif
1 秒是肯定可以了,1毫秒?........
MT4不提供方法,应该没有办法办到

MT4提供了SetMillionTimer()函数,我试过了,可以进行毫秒控制。查阅历史数据最小的TICK大约几十毫秒,语句执行时间在纳秒级,程序执行时间可以做到小于TICK时间。可以通过优化程序,提高执行速度。

柒侠伍义 发表于 2016-10-17 10:40:45

谷歌一下......
https://docs.mql4.com/eventfunctions/eventsetmillisecondtimer

EventSetMillisecondTimer
The function indicates to the client terminal that timer events should be generated at intervals less than one second for this Expert Advisor or indicator.
boolEventSetMillisecondTimer(
   intmilliseconds      // number of milliseconds
   );
Parameters
milliseconds
Number of milliseconds defining the frequency of timer events.

Returned value
In case of successful execution, returns true, otherwise - false. To receive an error code, GetLastError() function should be called.
Note
This feature is designed for the cases when high-resolution timer is required. In other words, timer events should be received more frequently than once per second. If a conventional timer with the period of several seconds is enough for you, use EventSetTimer().
Usually, this function should be called from OnInit() function or in class constructor. To handle events coming from the timer, an Expert Advisor or an indicator should have OnTimer() function.
Each Expert Advisor and each indicator work with its own timer receiving events solely from this timer. During mql4 application shutdown, the timer is forcibly destroyed in case it has been created but has not been disabled by EventKillTimer() function.
Only one timer can be launched for each program. Each mql4 application and chart have their own queue of events where all newly arrived events are placed. If the queue already contains Timer event or this event is in the processing stage, then the new Timer event is not added to mql4 application queue.

13611347809 发表于 2016-10-17 10:44:31

OK。

13611347809 发表于 2016-10-17 10:46:47

不在电脑旁,函数名笔误,见谅。

sunsky 发表于 2017-2-25 11:26:38

用计时器,无法回测。Timer and ChartEvent events are not handled in the Strategy Tester.
页: [1]
查看完整版本: 用毫米计时器代替TICK函数运算