I'm trying to use the TA_HT_* family of functions in TA-lib. I've been noticing a very strange thing: depending on how many outputs I ask, I get different values referring to the same inputs. Let me explain:
std::vector<double> results(prices.size());
std::vector<double> leadResults(prices.size());
int outBeg;
int outNbElement;
assert(prices.size() > TA_HT_SINE_Lookback());
TA_HT_SINE(0, prices.size() - 1, prices.data(), &outBeg, &outNbElement, results.data(), leadResults.data());
assert(outNbElement >= 1);
auto lastSine = results[outNbElement - 1];
(results contains 0.00143562, -0.0118441, ..., -0.318535, -0.278893) produces a different result (lastSine) than
std::array<double, 2> results;
std::array<double, 2> leadResults;
int outBeg;
int outNbElement;
assert(prices.size() > TA_HT_SINE_Lookback() + 1);
TA_HT_SINE(prices.size() - 2, prices.size() - 1, prices.data(), &outBeg, &outNbElement, results.data(), leadResults.data());
assert(outNbElement == 2);
auto lastSine = results[1];
(array contains: -0.300364, -0.264885) which in turn produces a different result (lastSine) than
double lastSine;
double lastLeadSine;
int outBeg;
int outNbElement;
assert(prices.size() > TA_TH_SINE_Lookback());
TA_HT_SINE(prices.size() - 1, prices.size() - 1, prices.data(), &outBeg, &outNbElement, &lastSine, &lastLeadSine);
assert(outNbElement == 1);
(here lastSine is -0.238856) why is that? Is it a bug in my code or in the TA lib? What I'm expecting is that I'm always computing the value related to the last price. I believe I'm driving the library as described in the docs.