MACD_R.C - Moving Average Convergence / Divergence Routines
ANSI C Moving Average Convergence / Divergence and Moving Average
Convergence / Divergence Histogram routines. All of the MACD routines
are front-ended by macros to provide the MACDH routines. And since an
MACD is just a dual moving average crossover with one more parameter
for a trigger line, the MACD routines have also been front-end by
another set of macros for DMAC support (the DMAC new macro will supply
a dummy value for the trigger line length). So once the enough_data is
field goes TRUE the DMAC value will be in the macd var.
For an example lets calc a McClellan Oscillator -
// given 2 float arrays of data : adv[] & decl[]
mcc_ptr = new_dmac_struct( 19 , 39 , FALSE ) ;
for( i = 0 ; 1 <40 ; i++ )
update_dmac_struct( mcc_ptr , adv[ i ] - decl[ i ] ) ;
printf( "McClellan Osc = %4.0f \n" , mcc_ptr->macd ) ;
Function
|
new_macd_struct
|
Include file
|
MACD_R.H
|
Prototype
|
MACD * new_macd_struct(
int ma_length1 , int ma_length2 , int trigger , int sma_flag )
|
Remarks
|
Allocate, initialize and return a virgin moving average convergence /
divergence structure. This same structure is also used for calculating
MACDHs and DMACs. Set sma_flag to TRUE to calculate simple moving
averages and FALSE for exponential averages.
|
Function
|
reset_macd_struct
|
Include file
|
MACD_R.H
|
Prototype
|
void reset_macd_struct( MACD *macd_ptr )
|
Remarks
|
Reset a MACD data structure for a new data series.
|
Function
|
update_macd_struct
|
Include file
|
MACD_R.H
|
Prototype
|
void update_macd_struct( MACD *macd_ptr , float data )
|
Remarks
|
Update the caller's MACD with the new data. Once we have collected enough
data to calc the MACD, macd_ptr->enough_data will be set to TRUE and
macd_ptr->macd can be used.
|
Function
|
free_macd_struct
|
Include file
|
MACD_R.H
|
Prototype
|
void free_macd_struct( MACD *macd_ptr )
|
Remarks
|
Return the MACD and its sub-structure memory to the system.
|
Function
|
calc_emacd
|
Include file
|
MACD_R.H
|
Prototype
|
void calc_emacd( MACD *macd_ptr , float data )
|
Remarks
|
Calculate a new output value for the given exponential MACD indicator
structure using the provided data.
|
Function
|
calc_smacd
|
Include file
|
MACD_R.H
|
Prototype
|
void calc_smacd( MACD *macd_ptr , float data )
|
Remarks
|
Calculate a new output value for the given simple MACD indicator structure
using the provided data.
|
Function
|
new_macd_ind_struct
|
Include file
|
MACD_R.H
|
Prototype
|
MACD_IND * new_macd_ind_struct( int data_cnt )
|
Remarks
|
Allocate, and return a virgin moving average convergence / divergence
indicator display structure for data_cnt items.
|
Function
|
free_macd_ind_struct
|
Include file
|
MACD_R.H
|
Prototype
|
void free_macd_ind_struct( MACD_IND *macd_ptr )
|
Remarks
|
Return the MACD indicator display structure and its sub-structure
memory to the system.
|
Function
|
calc_macd_ind
|
Include file
|
MACD_R.H
|
Prototype
|
void calc_macd_ind(
DATA_REC *data_ptr , int data_cnt , int which_field , MACD_IND *inds ,
int ma_length1 , int ma_length2 , int trigger , int sma_flag )
|
Remarks
|
Calculate a moving average convergence / divergence indicator of
ma_length1 and ma_length2 with a trigger length of trigger for the
requested field for the DATA_REC data series. The indicator will be built
in the caller's MACD_IND indicator display structure inds. While we are
at it we'll also calc the MACD histogram.
|
Table of Contents
Function Index
generated on 22 September 1998 - 12:55:09
© 1998 Tierra del Fuego Ltd.
|