Ticks per second

2019-08-20 03:25发布

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?

Many thanks for your answers!

标签: mql5
1条回答
疯言疯语
2楼-- · 2019-08-20 03:46

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++;}
}

if necessary, add ticksLastSecond in an array to average over last minute or any other period

查看更多
登录 后发表回答