WU Trading Library 0.2.0
A backtesting and trading strategy library
Loading...
Searching...
No Matches
indicators.h File Reference
#include "types.h"
#include "data.h"
#include <stdlib.h>
#include <math.h>

Go to the source code of this file.

Data Structures

struct  WU_SMA
 MovingAverage is a simple moving average indicator that calculates the average of the last N values, where N is the window size. More...
struct  WU_EMA
 The exponential moving average (WU_EMA) is a type of moving average that gives more weight to recent values, making it more responsive to recent value changes. More...
struct  WU_MVar
 The WU_MVar (Moving Variance) is an indicator that calculates the variance of the last N values, where N is the window size. More...
struct  WU_MStDev
 The WU_MStDev (Moving Standard Deviation) is an indicator that calculates the standard deviation of the last N values, where N is the window size. More...
struct  WU_RSI
 The WU_RSI (Relative Strength Index) is a momentum oscillator that measures the speed and change of price movements. More...
struct  WU_MACDResult
 The WU_MACDResult structure holds the current values of the MACD line, signal line, and histogram. More...
struct  WU_MACD
 The WU_MACD (Moving Average Convergence Divergence) is a trend-following momentum indicator that shows the relationship between two moving averages of a security's price. More...
struct  WU_MaxDrawdown
 Maximum Drawdown - tracks the largest peak-to-trough decline. More...
struct  WU_PerformanceUpdate
 Performance Update - value and timestamp for performance metric calculations. More...
struct  WU_Downside
 Tracks the average downside, calculate as the square root of the average of the squared negative values. More...
struct  WU_Mean
 A global mean calculator that updates with new values and maintains the current mean. More...
struct  WU_Var
 A glabal variance calculator. More...
struct  WU_StDev
 A global standard deviation calcular. More...

Macros

#define wu_indicator_update(indicator, value)
 Header file for technical indicators.
#define wu_indicator_get(indicator)
 Get the current value of the indicator.
#define wu_indicator_delete(indicator)
 Delete the indicator and free any resources allocated by it.

Functions

WU_SMA wu_sma_new (int window_size)
 Creates a new WU_SMA (Simple Moving Average) indicator with the specified window size.
WU_EMA wu_ema_new (int window_size, double smoothing)
 Creates a new WU_EMA (Exponential Moving Average) indicator with the specified period and smoothing factor.
WU_MVar wu_mvar_new (int window_size, int dof)
 Creates a new WU_MVar (Moving Variance) indicator with the specified window size and degree of freedom.
WU_MStDev wu_mstdev_new (int window_size, int dof)
 Creates a new WU_MStDev (Moving Standard Deviation) indicator with the specified window size and degree of freedom.
WU_RSI wu_rsi_new (int window_size)
 Creates a new WU_RSI (Relative Strength Index) indicator with the specified window size.
WU_MACD wu_macd_new (int short_window, int long_window, int signal_window, double smoothing)
 Creates a new WU_MACD (Moving Average Convergence Divergence) indicator with the specified short and long window sizes, and signal line window size.
WU_MaxDrawdown wu_max_drawdown_new (void)
 Creates a new WU_MaxDrawdown indicator.
WU_Downside wu_downside_new (void)
 Creates a new WU_Downside indicator.
WU_Mean wu_mean_new (void)
 Creates a new WU_Mean indicator.
WU_Var wu_var_new (int dof)
 Createas a new variance indicator.
WU_StDev wu_stdev_new (int dof)
 Creates a new standard deviation indicator.

Macro Definition Documentation

◆ wu_indicator_delete

#define wu_indicator_delete ( indicator)
Value:
(indicator)->delete((indicator))

Delete the indicator and free any resources allocated by it.

This macro assumes that the indicator has a delete function that takes the indicator itself and frees any resources allocated by it.

Definition at line 56 of file indicators.h.

◆ wu_indicator_get

#define wu_indicator_get ( indicator)
Value:
((indicator)->value)

Get the current value of the indicator.

This macro assume that the indicator has a value field that holds the current state of the indicator.

Definition at line 49 of file indicators.h.

◆ wu_indicator_update

#define wu_indicator_update ( indicator,
value )
Value:
(indicator)->update((indicator), (value))
static double update(WU_EMA ema, double value)
Definition ema.c:4

Header file for technical indicators.

Defines the structures and function prototypes for various indicators. All the indicator should follow the same interface:

  • update: A function that takes a new value (or candle) and updates the indicator's state, returning the new indicator value.
  • delete: A function that frees any resources allocated by the indicator.
  • value: A field that holds the current value of the indicator.

Once the indicator has been created, it should only be accessed using the provided macros:

This design allows for a consistent interface across different types of indicators, making it easier to use them interchangeably in trading strategies. Update the indicator state with a new value a return the updated indicator state. This macro assumes that the indicator has an update function that takes the indicator itself and a new value, and returns the updated indicator value.

Definition at line 41 of file indicators.h.

Function Documentation

◆ wu_downside_new()

WU_Downside wu_downside_new ( void )

Creates a new WU_Downside indicator.

Definition at line 23 of file mean_downside.c.

◆ wu_ema_new()

WU_EMA wu_ema_new ( int window_size,
double smoothing )

Creates a new WU_EMA (Exponential Moving Average) indicator with the specified period and smoothing factor.

Usually, 2.0 is used as the smoothing factor.

Definition at line 27 of file ema.c.

◆ wu_macd_new()

WU_MACD wu_macd_new ( int short_window,
int long_window,
int signal_window,
double smoothing )

Creates a new WU_MACD (Moving Average Convergence Divergence) indicator with the specified short and long window sizes, and signal line window size.

Definition at line 27 of file macd.c.

◆ wu_max_drawdown_new()

WU_MaxDrawdown wu_max_drawdown_new ( void )

Creates a new WU_MaxDrawdown indicator.

The initial value is set to 0 and the initial peak is set to the first portfolio value observed.

Definition at line 20 of file maxdrawdown.c.

◆ wu_mean_new()

WU_Mean wu_mean_new ( void )

Creates a new WU_Mean indicator.

Definition at line 15 of file mean.c.

◆ wu_mstdev_new()

WU_MStDev wu_mstdev_new ( int window_size,
int dof )

Creates a new WU_MStDev (Moving Standard Deviation) indicator with the specified window size and degree of freedom.

Definition at line 17 of file mstdev.c.

◆ wu_mvar_new()

WU_MVar wu_mvar_new ( int window_size,
int dof )

Creates a new WU_MVar (Moving Variance) indicator with the specified window size and degree of freedom.

Definition at line 32 of file mvar.c.

◆ wu_rsi_new()

WU_RSI wu_rsi_new ( int window_size)

Creates a new WU_RSI (Relative Strength Index) indicator with the specified window size.

Definition at line 24 of file rsi.c.

◆ wu_sma_new()

WU_SMA wu_sma_new ( int window_size)

Creates a new WU_SMA (Simple Moving Average) indicator with the specified window size.

Definition at line 22 of file sma.c.

◆ wu_stdev_new()

WU_StDev wu_stdev_new ( int dof)

Creates a new standard deviation indicator.

Definition at line 49 of file var.c.

◆ wu_var_new()

WU_Var wu_var_new ( int dof)

Createas a new variance indicator.

Definition at line 25 of file var.c.