我在MQL5中尝试了下面的代码,但是得到了错误。我猜这段代码来自MQL4。
代码:
int OnInit()
{
// if you don't want to execute on the first tick
IsBarClosed(-1,false);
return(1);
if(!IsBarClosed(0,true)) // true/false here allows to keep old bar for check again later in the code and reset
return(0);
}
//+------------------------------------------------------------------+
//| check if new bar has formed
//+------------------------------------------------------------------+
bool IsBarClosed(int timeframe,bool reset)
{
static datetime lastbartime;
if(timeframe==-1)
{
if(reset)
lastbartime=0;
else
lastbartime=iTime(NULL,timeframe,0);
return(true);
}
if(iTime(NULL,timeframe,0)==lastbartime) // wait for new bar
return(false);
if(reset)
lastbartime=iTime(NULL,timeframe,0);
return(true);
}输出:
'iTime' - function not defined testing lines and trdae.mq5 243 25
'iTime' - function not defined testing lines and trdae.mq5 246 8
'iTime' - function not defined testing lines and trdae.mq5 249 21
3 error(s), 0 warning(s) 4 1请帮助我用MQL5正确地完成它。我在试着检测蜡烛棒的关闭时间而不是打开时间。我只想在酒吧关门的时候试试。
发布于 2018-03-30 06:54:00
iTime()函数不存在于MQl5中,只存在于MQL4中。使用CopyRates()或SeriesInfoInteger(_Symbol,_Period,SERIES_LASTBAR_DATE)。static是MQL4 4/5中的关键字,具有非常特定的属性。许多版本的工作方式如下:如果将ea附加到图表中,则static为零,然后进行更新。如果你重新连接-从零到实际。如果您更改了ea/ind -静态的时间框架或设置,则保持不变(它不去初始化,不会变为零,然后变为实际值)。最早的1000+ MT4构建就是这样工作的(从现在起有两次更新)。也许有人发现这个关键字在mql4中很有用,它允许将变量与它们的函数放在一起,而不是在全局中;当然,要记住上面的问题,或者忽略它。但是没有理由在MQL5中使用这个词。如果您需要一组函数--创建一个类并保留与其相关的所有变量。然后,您将不会遇到未重新初始化的静态变量的问题。open time + PeriodSeconds(_Period)-1)。我不知道您为什么需要在代码中重置参数,请尝试以下操作:
datetime iTime=(datetime)(SeriesInfoInteger(_Symbol,Period(),SERIES_LASTBAR_DATE)/PeriodSeconds()*PeriodSeconds()); 然后将代码中的iTime()替换为iTime变量,这可能会有所帮助。
https://stackoverflow.com/questions/49569308
复制相似问题