// Alligator Indicator // // William Elder's Alligator uses three SMAs shifted forward in time: // Jaw: SMA(13) shifted 8 bars // Teeth: SMA(8) shifted 5 bars // Lips: SMA(5) shifted 3 bars // // X_n - 1 // Y_n - 3 // C_n - 0 #include "ts.h" ts_parameter_t const ts_alligator_p = { .n_inputs = 1, .n_outputs = 3, .n_constants = 0, .params_size = 0 }; uint_t ts_alligator_offset( ts_constant_t const *c ) { ( void )c; return ( 12 ); } int ts_alligator( fp_t * const *y, uint_t y_n, fp_t const * const *x, uint_t x_n, uint_t n, ts_constant_t const *c ) { TS_PROLOGUE( ts_alligator_p ); (void)c; /* Jaw: SMA(13) shifted 8 positions */ /* Teeth: SMA(8) shifted 5 positions */ /* Lips: SMA(5) shifted 3 positions */ /* Jaw: SMA13 of x[i-8..i+4], displayed at i */ for (uint_t i = 8; i - 8 + 13 <= n; ++i) { fp_t sum = 0; for (uint_t j = 0; j < 13; ++j) { sum += x[0][i - 8 + j]; } y[0][i] = sum / 13; } /* Teeth: SMA8 of x[i-5..i+2], displayed at i */ for (uint_t i = 5; i - 5 + 8 <= n; ++i) { fp_t sum = 0; for (uint_t j = 0; j < 8; ++j) { sum += x[0][i - 5 + j]; } y[1][i] = sum / 8; } /* Lips: SMA5 of x[i-3..i+1], displayed at i */ for (uint_t i = 3; i - 3 + 5 <= n; ++i) { fp_t sum = 0; for (uint_t j = 0; j < 5; ++j) { sum += x[0][i - 3 + j]; } y[2][i] = sum / 5; } return 0; }