Ticks per second

一世执手 提交于 2020-01-06 07:27:28

问题


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!


回答1:


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



来源:https://stackoverflow.com/questions/48600384/ticks-per-second

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!