how to limit custom indicator calculation to session bars
Posted: Sun Sep 01, 2019 11:19 pm
1. I am trying to calculate CVD (cumulative delta) only for bars I see on the screen, how do I limit the calculation to session profile or chart profile----code I am using to calculate CVD
Code: Select all
double cvd;
public long getInterval()
{
return Intervals.INTERVAL_15_SECONDS; // tell Bookmap how frequently to call onBar()
}
public void onInterval()
{
// We don't need the call itself, but it is guaranteed to be called with requested frequency
}
@Override
public void onTimestamp(long t)
{
if (barTime == null || barTime > t)
{
barTime = barInterval * (t / barInterval);
}
while (barTime + barInterval < t)
{
barTime += barInterval;
onBar();
bar.startNext();
}
}
void onTrade(double price, int size, TradeInfo tradeInfo)
{
if (tradeInfo.isBidAggressor)
cumbuyvol = cumbuyvol + size ;
else
cumsellvol = cumsellvol + size;
cvd = cumbuyvol - cumsellvol;
}