简体   繁体   English

MQL5 时间条件,每小时交易一次

[英]MQL5 Time condition, trade once per hours

does someone know a condition to trade only once per hour in mql5, i'm a begginer and having trouble to find something that i can undestand.有人知道在 mql5 中每小时只交易一次的条件吗,我是一个初学者,很难找到我无法理解的东西。 Thank you谢谢

This is very doable using the OnTimer function.使用OnTimer function 非常可行。 First, create the timer upon initialization:首先,在初始化时创建定时器:

 //--- create a timer with a 1 second period EventSetTimer(1);

Then, call the timer via the OnTimer method:然后,通过 OnTimer 方法调用定时器:

 //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { // Psst... you should set a flag (bool) in here }

As a friendly piece of advice, there is a ton of resources on stuff like this lying around the Mql forums and docs, definitely try to research stuff like this before posting a question.作为一个友好的建议,在 Mql 论坛和文档周围有大量关于此类内容的资源,请务必在发布问题之前尝试研究此类内容。

The best way is to simply have a time variable which you reset once per hour.最好的方法是简单地设置一个每小时重置一次的时间变量。

 datetime TimeBar; void OnTick() { if(TimeBar==iTime(_Symbol,PERIOD_H1,0)) return; //Code to open a trade goes here TimeBar=iTime(_Symbol,PERIOD_H1,0); return; }

As @PaulB said you can use iTime, but you can use OnTimerEvent too.正如@PaulB 所说,您可以使用 iTime,但您也可以使用OnTimerEvent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM