For balance velocity (this may be unchanged, not sure):
public BalanceVelocity(int fastPeriod, int slowPeriod) {
addParam(new Integer(fastPeriod));
addParam(new Integer(slowPeriod));
fastMultiplier = 2.0 / (fastPeriod + 1.0);
slowMultiplier = 2.0 / (slowPeriod + 1.0);
}
@Override
public void calculate() {
double balance = marketBook.getSnapshot().getBalance();
fast += (balance - fast) * fastMultiplier;
slow += (balance - slow) * slowMultiplier;
value = fast - slow;
}
And for acceleration I made a different indicator:
public class BalanceVelocityDerivative extends Indicator {
private final double balFastMultiplier, balSlowMultiplier, velFastMultiplier, velSlowMultiplier;
private double balFast, balSlow;
private double velFast, velSlow;
public BalanceVelocityDerivative(int balanceFastPeriod, int balanceSlowPeriod, int velocityFastPeriod, int velocitySlowPeriod) {
addParam(new Integer(balanceFastPeriod));
addParam(new Integer(balanceSlowPeriod));
addParam(new Integer(velocityFastPeriod));
addParam(new Integer(velocitySlowPeriod));
balFastMultiplier = 2.0 / (balanceFastPeriod + 1.0);
balSlowMultiplier = 2.0 / (balanceSlowPeriod + 1.0);
velFastMultiplier = 2.0 / (velocityFastPeriod + 1.0);
velSlowMultiplier = 2.0 / (velocitySlowPeriod + 1.0);
}
@Override
public void calculate() {
double velocity;
double balance = marketBook.getSnapshot().getBalance();
balFast += (balance - balFast) * balFastMultiplier;
balSlow += (balance - balSlow) * balSlowMultiplier;
velocity = balFast - balSlow;
velFast += (velocity - velFast) * velFastMultiplier;
velSlow += (velocity - velSlow) * velSlowMultiplier;
value = velFast - velSlow;
}
@Override
public void reset() {
balFast = balSlow = velFast = velSlow = value = 0;
}
}
I set the velocity fast and slow periods to be much smaller than the balance periods (which I think are the same periods I use for the first indicator).
As a general rule of thumb I set all the periods short enough that the trends make sense when I look at them in the graph window. Some of the example strategies have the periods set so long that they don't make any sense when I look at them! (Although they still yield profitable results...)
Anyways, I made a strategy that makes good profits using the techniques we just talked about, but only on the long side in the example data. Short side is not so good. (I tend to split strategies into two parts, a long strategy, and a short strategy, and I optimize them independently.)