柱状图和成交量对于检测新的柱状图 是不可靠的。
计算机的工作时间是纳米级的,所以一个编码良好的EA可以在20毫秒内做很多事情。
- 2010.10.11
- Konstantin Gruzdev
- www.mql5.com
- www.mql5.com
谢谢你,阿兰。
非常有趣......正是我所猜想的......。10倍的速度......嗯。
这意味着。TimeCurrent()是快速的,并且与条形边界同步?
为什么.... hmmm ...
我需要一点时间来考虑这个问题。
尊敬的Willbur先生
好吧--对于喜欢这样东西的人来说:我对这个问题的研究。
我在每个 "OnTick "事件中都写了一句话到文件中。
TimeLocal (PC CLock), TimeCurrent(), 使用SymbolInfoTick()关于最后一个tick的一些信息,以及-使用CopyRates()-关于当前Bar的一些信息。
一个来自 "USD/JPY "的例子 - 期间是 "M1"。
当第43分钟的第一个刻度出现时,PC时钟上的时间是19:43:01,同时出现了一个新的条形图。
除了嘀嗒声-音量不是1之外,这就是正常的事情流程。
有时它并不那么容易--比如在这种情况下。
当41分钟条形图的另外三个刻度出现时,PC显示已经是19:42:00。他们的时间戳仍然是19:41:59。
现在,世界深吸一口气--8.150毫秒的完全静止。
然后--电脑显示已经是19:42:09了--新条形图的第一个刻度--42分钟条形图--出现了。
该刻度线被标记为19:42:07,并且--因为它是19:42的条形图,所以条形图的时间戳是19:42:00。
现在.... hmmm ....
1.TimeCurrent()是否总是等于刻度线的时间戳?
我检查了40,000条记录,发现只有五种情况下,TimeCurrent已经转换,而最后一个Tick的时间戳没有转换。
2.2.last_tick是否总是比新条形图的开盘时间早?
(待续)
TimeCurrent()是来自服务器的最后一个刻度的时间,这取决于你的代码是否来自你的图表符号。
我不明白你的 "最后一格 "问题,你应该显示产生这种输出的代码。
你好,阿兰
我检查了 OnTick()中的TimeCurrent(),这应该确保它属于我处理的符号。
那么,这应该是我的 "新条形标识符"--小而快--你怎么看?
//--- New Bar
bool NewBar = false;
long currPeriodSeconds;
double currPeriodProgress = 0;
int OnInit(void) //-----------------------------------------------
{
currPeriodSeconds = PeriodSeconds();
return(INIT_SUCCEEDED);
}
void OnTick() //--------------------------------------------------
{
if(MathMod(TimeCurrent(),currPeriodSeconds) < currPeriodProgress)
NewBar = true;
else NewBar = false;
currPeriodProgress = MathMod(TimeCurrent(),currPeriodSeconds);
我打算用这个序列来检查它。
//--- Just for testing
int ExtHdlFile1=0;
MqlRates rates[1];
//--- New Bar
bool NewBar = false;
long currPeriodSeconds;
double currPeriodProgress = 0;
int OnInit(void) // -------------------------------------------------------
{
currPeriodSeconds = PeriodSeconds();
ExtHdlFile1=FileOpen("NewBarTest.csv",FILE_READ|FILE_WRITE|FILE_CSV);
FileSeek (ExtHdlFile1,0,SEEK_END);
FileWrite(ExtHdlFile1, "TimeLocal",
"TimeCurrent",
"rates[0].time",
"rates[0].tick");
return(INIT_SUCCEEDED);
}
void OnTick() // -----------------------------------------------------------
{
if(MathMod(TimeCurrent(),currPeriodSeconds) < currPeriodProgress)
NewBar = true;
else NewBar = false;
currPeriodProgress = MathMod(TimeCurrent(),currPeriodSeconds);
//--- lets check this
if(NewBar)
{
// last Time Stamp of old Bar
FileWrite(ExtHdlFile1, " ",
" ",
TimeToString(rates[0].time, TIME_MINUTES|TIME_SECONDS),
IntegerToString(rates[0].tick_volume));
// get the new bar
if(CopyRates(Symbol(),Period(),0,1,rates)!= 1) return;
// first Time Stamp of new Bar
FileWrite(ExtHdlFile1,TimeToString(TimeLocal(),TIME_MINUTES|TIME_SECONDS),
TimeToString(TimeCurrent(), TIME_MINUTES|TIME_SECONDS),
TimeToString(rates[0].time, TIME_MINUTES|TIME_SECONDS),
IntegerToString(rates[0].tick_volume));
}
if(CopyRates(Symbol(),Period(),0,1,rates)!= 1) return; // != clean code - just a test
}
void OnDeinit(const int reason)
{
FileClose(ExtHdlFile1);
return;
}
这是我的最终版本。
事实上,我有点担心,因为这太容易了。
阿兰。如果你能发出祝福,那就太好了。
// -----------------------------------------------------------------------
bool NewBar(void)
{
bool iNewBar = false;
static double currPeriodProgress = 0;
currPeriodProgress = MathMod(TimeCurrent(),PeriodSeconds());
return(iNewBar);
}
// ------------------------------------------------------------------------
void OnTick()
{
if(NewBar()) PlaySound("tick.wav");
来自科隆的问候
威尔伯
最简单的方法。
static datetime tlastbar=0;
datetime tnewbar=iTime(NULL,PERIOD_CURRENT,0)。
bool isnewbar=tnewbar!=tlastbar。
tlastbar=tnewbar。
我想知道如何显示一个新的柱状体是什么时候出现的。
我主要是担心性能问题。在一些符号上,我看到每隔20毫秒就有一个刻度。没有那么多的时间来反应。
一个想法是rate.tick_volume
Mqlrates rates[1];
OnInit()
{
if(CopyRates(_Symbol,_Period,0,1,rates) < 1)
if(rates[0].tick_volume == 1)
{
... deal with new bar ...
}
另一个想法是检查柱状图的数量 是否已经增加。
OnInit()
{
if(BarsOld < Bars(_Symbol,_Period))
{
BarsOld = Bars(_Symbol,_Period);
... deal with new bar ...
}
我也检查了OnChartEvent,但我发现没有办法区分新条形和其他东西。
谢谢你的评价
吕晓波