Volume imprint calculation method

BreakEvenORDeath

New member
Joined
Sep 16, 2025
Posts
2
Likes
1
Hello,

I’ve been trying to replicate the Volume Imprint bid/ask calc method from the code i found in an old thread with a custom study, but I keep running into accuracy issues.

It is close/equal 90% of the time but in rare cases it can be way too far off.

What I'm doing:

I have a custom study that calculates delta per bar using tick data. For each bar, I replay ticks via
Instrument.forEachTick() and classify each tick using Tick.isAskTick():

synchronized void onTick(Tick tick) {
Float price = tick.getPrice();
Integer volume = tick.getVolume();
if (price == null || volume == null || volume == 0) return;

boolean isBuy = tick.isAskTick();
if (isBuy) {
askVolume += volume;
} else {
bidVolume += volume;
}
}

long getDelta() { return askVolume - bidVolume; }
long getVolume() { return askVolume + bidVolume; }

I also tried using VolumeProfile since the volume imprint deleguates the calculation to this class:

Class<?> vpClass = Class.forName("com.motivewave.platform.study.volume.VolumeProfile");
Constructor<?> vpConstructor = vpClass.getConstructor(long.class, long.class, Instrument.class, int.class);
Method vpOnTick = vpClass.getMethod("onTick", Tick.class);
Method vpGetRows = vpClass.getMethod("getRows");

// Create per bar:
Object vp = vpConstructor.newInstance(barStart, barEnd, instrument, 1);

// Feed each tick:
vpOnTick.invoke(vp, tick);

// Sum delta from all rows:
List<?> rows = (List<?>) vpGetRows.invoke(vp);
long totalDelta = 0;
for (Object row : rows) {
totalDelta += ((Number) rowGetDelta.invoke(row)).longValue();
}

Neither approach matches the native Volume Imprint exactly. The delta is close on most bars but on some bars it's
noticeably different.

I would like to exactly replicate the total delta/bar just like the volume imprint.

Any help would be appreciated.
 

Attachments

Top