问题描述
我想计算每秒的价格变动数(或价格变动).不幸的是,MQL5的 ENUM_TIMEFRAMES 只能保留1分钟. 此指标证明有可能,但是如何?也许通过 OnTimer事件?
I would like to calculate the number of ticks (or alternatively the price change) per second. Unfortunately MQL5's ENUM_TIMEFRAMES only goes down to 1 min. This indicator proves it's possible, though, but how? Maybe by means of the OnTimer event?
非常感谢您的回答!
推荐答案
datetime
时间是自新计算机时代以来的秒数.如果您调用返回datetime
的TimeCurrent()
,它将为您提供整数.如果您在0.1秒内再次调用它,您将收到相同的整数(或same + 1).指标可以计算OnCalculate()中的滴答数,并与以前的时间进行比较.像这样的东西:
datetime
time is number of seconds since the new computer era. if you call TimeCurrent()
that returns datetime
, it will give you integer. if you call it again in 0.1 second, you will receive same integer (or same+1). The indicator may count number of ticks in OnCalculate() and comparing with old time.something like this:
datetime lastTime;
int ticksLastSecond;
OnCalculate(***){
if(TimeCurrent()>lastTime){
lastTime=TimeCurrent();ticksLastSecond=1;
}else{ticksLastSecond++;}
}
如有必要,将一个数组中的ticksLastSecond
添加到最后一分钟或任何其他时间段的平均值
if necessary, add ticksLastSecond
in an array to average over last minute or any other period
这篇关于每秒滴答声的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!