0

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.

Stefano Falasca
  • 8,837
  • 2
  • 18
  • 24
  • 1
    Why don't you print the whole inputs and outputs to the console, compare them or use a Debugger like GDB to expore the values? – nada Mar 15 '19 at 14:35
  • Imho, this func seems to use WMA https://sourceforge.net/p/ta-lib/code/HEAD/tree/trunk/ta-lib/c/src/ta_func/ta_HT_SINE.c#l291 and moving average values are known to depend on where you started to calc them. They converge in long term. – truf Mar 24 '19 at 14:58
  • I thought that since "prices" is always the same vector (i.e. holding the same data) the computation would start from the beginning anyways. Isn't the only difference in how much data I want to get out of the library? – Stefano Falasca Mar 27 '19 at 10:39

0 Answers0