I'm getting strange results from the TA-LIB Mama indicator.
Calls to other indicators using the same price array give correct results.
But calls to core.mama()
give Mama values a pip or two out, and Fama values up to 30 pips out. I'm comparing to the values in JForex, which I've validated against other platforms.
I'm setting the length of the price array with a call to TA-LIB, but a longer lookback doesn't improve results:
int priceLength = core.mamaLookback(fastLimit, slowLimit) + 1;
My settings for the fastLimit and slowLimit are within sensible limits.
Changing the startIdx
param to 0 and returning more values doesn't help either.
The code is so simple that it's hard to see what I could be doing wrong. Am I having some kind of brain fart, or is the library bugged?
public static double[] runMama(double[] prices, double fastLimit, double slowLimit) {
try {
MInteger outBegIdx = new MInteger();
MInteger outNbElement = new MInteger();
int count = prices.length;
Core core = new Core();
// We only need the most recent value.
double[] outputFama = new double[1];
double[] outputMama = new double[1];
RetCode retCode = core.mama(count-1, count-1, prices, fastLimit, slowLimit, outBegIdx, outNbElement, outputMama, outputFama);
if (retCode != RetCode.Success) {
throw new RuntimeException("TA-LIB Mama has barfed!");
}
return new double[]{outputMama[0], outputFama[0]};
} catch (Exception e) {
Printer.printErr("Problem with MESA", e);
return null;
}
}
OK - my bad
I hadn't realised that Java TA-Lib returns data in a somewhat eccentric fashion.
In contrast to pretty much every other trading library the most recent values have the higher keys, with the highest keys being padded with a number of zero values related to the length of the lookback.
Also, when indicators have memories (like the Mama which is based on an exponential MA), you need a much longer lookback than the value returned by core.mamaLookback(fastLimit, slowLimit)
to get a meaningful result. So you need to pass in a long enough price array.
I'm now getting reliable results.