Signature | Description | Parameters |
---|---|---|
#include <DataFrame/DataFrameFinancialVisitors.h> template<typename T, typename I = unsigned long, std::size_t A = 0> struct TrixVisitor; // ------------------------------------- template<typename T, typename I = unsigned long, std::size_t A = 0> using trix_v = TrixVisitor<T, I, A>; |
This is a “single action visitor”, meaning it is passed the whole data vector in one call and you must use the single_act_visit() interface. This visitor calculates the balance of power indicator. It requires 4 input columns in the order of low, high, open, close. The result is a vector of values with same number of items as the given columns. The first item, in the result will be NaN, if signal_roll_period is false. If avg_signal is true, the first signal_roll_period - 1 will be NaN Developed by Jack Hutson in the early 1980s, the triple exponential average (TRIX) has become a popular technical analysis tool to aid chartists in spotting diversions and directional cues in stock trading patterns. Although many consider TRIX to be very similar to MACD, the primary difference between the two is that TRIX outputs are smoother due to the triple smoothing of the exponential moving average (EMA). As a powerful oscillator indicator, TRIX can be used to identify oversold and overbought markets, and it can also be used as a momentum indicator. Like many oscillators, TRIX oscillates around a zero line. When it is used as an oscillator, an extreme positive value indicates an overbought market while an extreme negative value indicates an oversold market. explicit TrixVisitor (size_type roll_period = 14, bool avg_signal = false, size_type signal_roll_period = 7); rolling_avg: Averaging period for triple exponential average avg_signal: If true, the resulting return is averaged in a simple rolling window signal_roll_period: rolling period for averaging the return, if avg_signal is true |
T: Column data type I: Index type A: Memory alignment boundary for vectors. Default is system default alignment |
static void test_TrixVisitor() { std::cout << "\nTesting TrixVisitor{ } ..." << std::endl; typedef StdDataFrame<std::string> StrDataFrame; StrDataFrame df; try { df.read("data/SHORT_IBM.csv", io_format::csv2); trix_v<double, std::string> trix; df.single_act_visit<double>("IBM_Close", trix); assert(trix.get_result().size() == 1721); assert(std::isnan(trix.get_result()[0])); assert(std::abs(trix.get_result()[4] - 0.0009) < 0.0001); assert(std::abs(trix.get_result()[14] - 0.0001) < 0.0001); assert(std::abs(trix.get_result()[18] - -0.001) < 0.0001); assert(std::abs(trix.get_result()[25] - -0.0024) < 0.0001); assert(std::abs(trix.get_result()[1720] - -0.0027) < 0.0001); assert(std::abs(trix.get_result()[1712] - 0.0008) < 0.0001); assert(std::abs(trix.get_result()[1707] - 0.0003) < 0.0001); trix_v<double, std::string> trix2 (14, true); df.single_act_visit<double>("IBM_Close", trix2); assert(trix2.get_result().size() == 1721); assert(std::isnan(trix2.get_result()[0])); assert(std::isnan(trix2.get_result()[5])); assert(std::abs(trix2.get_result()[6] - 0.0008) < 0.0001); assert(std::abs(trix2.get_result()[14] - 0.0003) < 0.0001); assert(std::abs(trix2.get_result()[18] - -0.0002) < 0.0001); assert(std::abs(trix2.get_result()[25] - -0.0019) < 0.0001); assert(std::abs(trix2.get_result()[1720] - -0.0011) < 0.0001); assert(std::abs(trix2.get_result()[1712] - 0.0006) < 0.0001); assert(std::abs(trix2.get_result()[1707] - -0.0005) < 0.0001); } catch (const DataFrameError &ex) { std::cout << ex.what() << std::endl; } }