WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
mean.c
Go to the documentation of this file.
1#include "wu/indicators.h"
2
3static double update(WU_Mean self, double value) {
4 if (isnan(value)) return NAN;
5 self->count++;
6 self->accum += value;
7 self->value = self->accum / self->count;
8 return self->value;
9}
10
11static void delete(WU_Mean self) {
12 free(self);
13}
14
15WU_Mean wu_mean_new(void) {
16 WU_Mean m = malloc(sizeof(struct WU_Mean_));
17 if (!m) return NULL;
18 m->count = 0;
19 m->accum = 0.0;
20 m->value = NAN;
21 m->update = update;
22 m->delete = delete;
23 return m;
24}
static double update(WU_EMA ema, double value)
Definition ema.c:4
WU_Mean wu_mean_new(void)
Creates a new WU_Mean indicator.
Definition mean.c:15
static double update(WU_Mean self, double value)
Definition mean.c:3
A global mean calculator that updates with new values and maintains the current mean.
Definition indicators.h:267