问题
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