Hi,
among the indicators I am trying to implement a simple problem reoccurs, I
try to make an indicator which is derived of another one. This can also be
seen in the initial set of indicators, where the same kind of combination
reoccurs. What I now tried to do was to find a standard way of generating
indicators from other ones.
The example below shows this for the "first derivative", which can make
sense for any kind of indicator.
The problem is, it is not really working. There is probably a bloody stupid
programming oversight, but at this point I fail to be able to identify it.
The corresponding class:
package com.jbooktrader.indicator.myindicators;
import com.jbooktrader.platform.indicator.*;
/**
* Velocity of price
* Modified KS: to describe modification speed
*/
public class MyDerivate extends Indicator {
private final double multiplier;
private double last;
private double curr;
Boolean first = true;
Indicator baseInd;
public MyDerivate(int Period, Indicator ind) {
super(Period);
multiplier = 2.0 / (Period + 1.0);
baseInd = ind;
last = 0;
}
@Override
public void calculate() {
double indVal = baseInd.getValue();
if (!(first)) {
curr = (indVal - last) * multiplier + (1-multiplier) * curr;
}
last = indVal;
value = curr; // don't share the global variable value (it might
lead to defects)
}
@Override
public void reset() {
last = 0; first = true;
}
}
The funny thing is: if we use it with an existing indicator, it works (not
quite correctly, as there are multiple calls per time frame), but if I use
it as follows:
balanceVelocityInd = addIndicator(new BalanceVelocity(getParam(
FAST_PERIOD), getParam(SLOW_PERIOD)));
balanceVelocityDerivInd = addIndicator(new MyDerivate(getParam(
CHANGE_PERIOD), new BalanceVelocity(getParam(FAST_PERIOD), getParam(
SLOW_PERIOD))));
the double indVal = baseInd.getValue();
actually delivers 0 !!
in the computation of the derivative..
Now, I am completely at a loss, where the problem comes from and what to
change to make this more
correct.
I have my doubts that
balanceVelocityDerivInd = addIndicator(new MyDerivate(getParam(CHANGE_PERIOD
), balanceVelocityInd));
would actually do the trick as in this case the indicator would be called
two times rather differently and I am afraid this would lead to
interactions.
But I have to admit I understand to little of the inner working of the
indicator framework to clearly determine this.
Any ideas / suggestions for how to do this correctly and why the
implementation above is not working?
Klaus
--
You received this message because you are subscribed to the Google Groups
"JBookTrader" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/jbooktrader/-/76-g9FuIHSMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jbooktrader?hl=en.