IND_ENG.C - INDicator ENGine routines
A subsystem to easily run multiple indicators and systems in parallel
against a data set and then generate a custom report for the user.
Function
|
get_trade_signal
|
Include file
|
IND_ENG.H
|
Prototype
|
char * get_trade_signal( int signal )
|
Remarks
|
Use the signal value to index into an array of char strs of trade
signals and market state messages.
|
Function
|
set_token_ptrs
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_token_ptrs( char *input_line )
|
Remarks
|
This is the first major routine used to parse the user's template line into
something meaningful. This routine will init all line parse vars and
ie_tokens[] array. It will then break the input_line into white-space
delimited NULL terminated token strings (this means input_line is changed).
At exit the the array token_cnt is set and the ie_tokens[].str sections look
like a AWK $1 , $2 .. $N token array (this means ie_tokens[ 0 ].str contains
the first token on the line, etc.).
|
Function
|
set_token_flags
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_token_flags( void )
|
Remarks
|
Now that the ie_tokens[] array is built, we'll try is see if we can recognize
any of the tokens as special flag verbs. If we do - hit the appropriate
special flag and mark the token as used.
|
Function
|
special_token_saves
|
Include file
|
IND_ENG.H
|
Prototype
|
void special_token_saves( void )
|
Remarks
|
Now handle the parentheses and equal sign assignments (and mark as
used). Also update the cur_prc_rec->spec_output_flag if necessary.
|
Function
|
get_first_int_arg
|
Include file
|
IND_ENG.H
|
Prototype
|
int get_first_int_arg( void )
|
Remarks
|
Return the first token string after the primary verb that begins with
a digit and don't worry if it has been used yet. Return 0 if none found.
|
Function
|
get_first_unused_int_arg
|
Include file
|
IND_ENG.H
|
Prototype
|
int get_first_unused_int_arg( void )
|
Remarks
|
Return the first token string after the primary verb that begins with
a digit and this time check that it hasn't been used yet. Mark it as now
having been used. Return 0 if none found.
|
Function
|
get_first_unused_arg
|
Include file
|
IND_ENG.H
|
Prototype
|
char * get_first_unused_arg( void )
|
Remarks
|
Get the first unused argument of any type. If we are parsing a math
operation then we start with the first token str else we skip the primary
verb token and begin searching at the next token. Return NULL if none found.
|
Function
|
get_first_unused_arg_n_mark_used
|
Include file
|
IND_ENG.H
|
Prototype
|
char * get_first_unused_arg_n_mark_used( void )
|
Remarks
|
Get the first unused argument of any type. If we are parsing a math
operation then we start with the first token str else we skip the primary
verb token and begin searching at the next token. This time mark the found
one as used. Return NULL if none found.
|
Function
|
get_label_str
|
Include file
|
IND_ENG.H
|
Prototype
|
char * get_label_str( void )
|
Remarks
|
Try a number of sources to generate a label str for the cur_prc_rec. First
check if the user gave us one, if so, return a clone of it. Then check if
the cur_prc_rec is something other than a file constant. If it is and the
cur_prc_rec->spec_proc_flag does not have the NO_SIZE bit set then build a
label str consisting df_label[ verb_idx] plus the size value the user gave
us. Else just return the df_label[ verb_idx ].
|
Function
|
get_unused_label_str
|
Include file
|
IND_ENG.H
|
Prototype
|
char * get_unused_label_str( void )
|
Remarks
|
Scan the tokens and return the first unused label_str (and mark it as used)
or return NULL.
|
Function
|
get_label_str_secondary
|
Include file
|
IND_ENG.H
|
Prototype
|
char * get_label_str_secondary( int src_idx , int size )
|
Remarks
|
Return a copy of the secondary data source's label str. If size != 0
append it to the label str too.
|
Function
|
make_secondary_label_str
|
Include file
|
IND_ENG.H
|
Prototype
|
void make_secondary_label_str( char *buffer , char *df_msg )
|
Remarks
|
Check if we have an available user supplied label str and either copy it
(if found) else the df_msg into the caller's buffer.
|
Function
|
set_data_source_n_labels
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_data_source_n_labels( int size )
|
Remarks
|
Set the data_source and label_str for the cur_prc_rec. Also hook the
label_str to the right slot in the ref_strs[ output_cnt ].
|
Function
|
chk_4_label_update_with_defaults
|
Include file
|
IND_ENG.H
|
Prototype
|
void chk_4_label_update_with_defaults( int size , char *use_this_label )
|
Remarks
|
If the user didn't give us a size on an indicator that has defaults, we
need to update the label_str with the indicator's default size. Also hook
the label_str to the right slot in the ref_strs[ output_cnt ].
|
Function
|
bld_ind_label_str
|
Include file
|
IND_ENG.H
|
Prototype
|
void bld_ind_label_str( char *base_str , int df_length )
|
Remarks
|
Build a indicator label str and hook it up to the ref_strs[ output_cnt ]
array.
|
Function
|
ie_get_format_str
|
Include file
|
IND_ENG.H
|
Prototype
|
char * ie_get_format_str( void )
|
Remarks
|
Return either the user provided format str else the df_formats[ verb_idx ].
|
Function
|
report_unused_tokens
|
Include file
|
IND_ENG.H
|
Prototype
|
void report_unused_tokens( void )
|
Remarks
|
OK everything is parsed, check if we've got anything marked as still
unused. If so, tell the user.
|
Function
|
set_output_formats
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_output_formats( void )
|
Remarks
|
Set the default price data output format str (depending on output_places).
|
Function
|
clone_cur_prc_rec
|
Include file
|
IND_ENG.H
|
Prototype
|
void clone_cur_prc_rec( char *label_str , int no_out_flag , int no_tsig_flag )
|
Remarks
|
Clone a copy of the cur_prc_rec, update the ref_strs[ output_cnt ] array.
At exit the cur_prc_rec will point to the new PRC_REC.
|
Function
|
inc_cur_prc_rec
|
Include file
|
IND_ENG.H
|
Prototype
|
void inc_cur_prc_rec( void )
|
Remarks
|
Since prc_master->prc_rec[] is an array of ptrs a simple cur_prc_rec++
won't work.
|
Function
|
dec_cur_prc_rec
|
Include file
|
IND_ENG.H
|
Prototype
|
void dec_cur_prc_rec( void )
|
Remarks
|
ditto
|
Function
|
dump_ticker_str
|
Include file
|
IND_ENG.H
|
Prototype
|
void dump_ticker_str( char *ticker )
|
Remarks
|
Dump the ticker str to the report and to the user so he sees that
something is happening.
|
Function
|
rpt_template_error
|
Include file
|
IND_ENG.H
|
Prototype
|
void rpt_template_error( char *msg )
|
Remarks
|
Report that a error occured in parsing a template line.
|
Function
|
ln_to_upper_except_in_dquotes
|
Include file
|
IND_ENG.H
|
Prototype
|
void ln_to_upper_except_in_dquotes( char *str )
|
Remarks
|
Convert all lower case characters in a str to upper case except the
characters in between double quotes.
exp - this is a "test" becomes THIS IS A "test"
|
Function
|
eat_commas_except_in_dquotes
|
Include file
|
IND_ENG.H
|
Prototype
|
void eat_commas_except_in_dquotes( char *str )
|
Remarks
|
Change all commas found in a str to spaces except the ones inside
of double quotes.
|
Function
|
eat_white_space_in_str
|
Include file
|
IND_ENG.H
|
Prototype
|
void eat_white_space_in_str( char *src , char *dest ) // do the tighten-up
|
Remarks
|
Delete all white_space from a str.
|
Function
|
is_this_a_number_str
|
Include file
|
IND_ENG.H
|
Prototype
|
int is_this_a_number_str( char *target )
|
Remarks
|
Return TRUE is the target str is a number else FALSE.
|
Function
|
strncpy_n_blank_pad
|
Include file
|
IND_ENG.H
|
Prototype
|
void strncpy_n_blank_pad( char *dest , char *src , int len )
|
Remarks
|
Do a strncpy then space pad to the caller's request length.
|
Function
|
rpt_memory_left_if_debug_flag
|
Include file
|
IND_ENG.H
|
Prototype
|
void rpt_memory_left_if_debug_flag( void )
|
Remarks
|
If the debug_flag == TRUE then report currently available near memory.
|
Function
|
dump_prc_master_if_debug_flag
|
Include file
|
IND_ENG.H
|
Prototype
|
void dump_prc_master_if_debug_flag( void )
|
Remarks
|
If the debug_flag == TRUE then dump all the allocated process_records.
|
Function
|
output_cur_prc_rec
|
Include file
|
IND_ENG.H
|
Prototype
|
void output_cur_prc_rec( void )
|
Remarks
|
Dump a debug look at the process_record pointed at by cur_prc_rec.
|
Function
|
dump_ref_str_if_debug_flag
|
Include file
|
IND_ENG.H
|
Prototype
|
void dump_ref_str_if_debug_flag( void )
|
Remarks
|
If debug_flag == TRUE dump the whole ref_strs[] array.
|
Function
|
clear_the_prc_array
|
Include file
|
IND_ENG.H
|
Prototype
|
void clear_the_prc_array( void )
|
Remarks
|
Init all the process_records in the prc_master struct and call their
individual init_routines (if they have one).
|
Function
|
chk_4_post_proc_requests
|
Include file
|
IND_ENG.H
|
Prototype
|
void chk_4_post_proc_requests( void )
|
Remarks
|
Check for any post DATA_REC processing special requests.
|
Function
|
save_trade_signal_value
|
Include file
|
IND_ENG.H
|
Prototype
|
void save_trade_signal_value( int idx , int store_value )
|
Remarks
|
Update the out_ptr->signal_state[ idx ] with the requested new store_value
and handle forward_time processing.
|
Function
|
save_output_value
|
Include file
|
IND_ENG.H
|
Prototype
|
void save_output_value( float store_value )
|
Remarks
|
Update the out_ptr->data[ cur_prc_rec->output_idx ] with the requested
new store_value. Also handle user log requests and forward_time
processing.
|
Function
|
output_str_2_log_file
|
Include file
|
IND_ENG.H
|
Prototype
|
void output_str_2_log_file( char *str )
|
Remarks
|
Hook to here to allow support for user requested last N records.
|
Function
|
get_data_value
|
Include file
|
IND_ENG.H
|
Prototype
|
float get_data_value( void )
|
Remarks
|
Fetch the current value for the defined data_source for the cur_prc_rec.
This could be either a file constant or a previously calculated process
record. The GLOBAL var last_data_value is also set.
|
Function
|
general_data_store
|
Include file
|
IND_ENG.H
|
Prototype
|
void general_data_store( void )
|
Remarks
|
A generalized data store for all the file constants.
|
Function
|
cnvt_tbond_vars_if_necessary
|
Include file
|
IND_ENG.H
|
Prototype
|
void cnvt_tbond_vars_if_necessary( void )
|
Remarks
|
If bond_decimal == TRUE, find all process_records with their PRICE_DATA
bit set in spec_proc_flag and convert their output values back to T-Bond
1/32s format.
|
Function
|
init_out_array
|
Include file
|
IND_ENG.H
|
Prototype
|
void init_out_array( void )
|
Remarks
|
Init out_array to a double linked circular queue.
|
Function
|
clear_the_out_array
|
Include file
|
IND_ENG.H
|
Prototype
|
void clear_the_out_array( void )
|
Remarks
|
Clear all the out_ptr's data and signal_state buckets for all the
process records.
|
Function
|
output_the_out_array
|
Include file
|
IND_ENG.H
|
Prototype
|
void output_the_out_array( void )
|
Remarks
|
OK the processing is all done so dump the out_array to output_device and
give the user his report.
|
Function
|
compare_dates
|
Include file
|
IND_ENG.H
|
Prototype
|
static int compare_dates( float date1 , float date2 )
|
Remarks
|
A simple compare function that returns values like strcmp, 0 = match,
-1 = date1 date2.
|
Function
|
find_rec_by_date
|
Include file
|
IND_ENG.H
|
Prototype
|
int find_rec_by_date( float target_date )
|
Remarks
|
Given a already open data file, search forward with retrys for a target
date. Calls find_rec_by_date2 for each attempt.
|
Function
|
find_rec_by_date2
|
Include file
|
IND_ENG.H
|
Prototype
|
static int find_rec_by_date2( float target_date )
|
Remarks
|
This routine will search a file for a target_date.
|
Function
|
test_find_rec_by_date
|
Include file
|
IND_ENG.H
|
Prototype
|
int test_find_rec_by_date( void )
|
Remarks
|
|
Function
|
load_secondary_data
|
Include file
|
IND_ENG.H
|
Prototype
|
void load_secondary_data( void )
|
Remarks
|
Load any user requested secondary data files into far memory DATA_REC
arrays for the whole program run.
|
Function
|
init_secondary_data_ptrs
|
Include file
|
IND_ENG.H
|
Prototype
|
void init_secondary_data_ptrs( void )
|
Remarks
|
Set the cur_sd?_rec and last_sd?_rec ptrs to the beginning of the
secondary data DATA_REC arrays.
|
Function
|
increment_secondary_data_ptrs
|
Include file
|
IND_ENG.H
|
Prototype
|
void increment_secondary_data_ptrs( void )
|
Remarks
|
Advanced the secondary data DATA_REC array ptrs.
|
Function
|
init_forward_data
|
Include file
|
IND_ENG.H
|
Prototype
|
void init_forward_data( void )
|
Remarks
|
Simulate new data by setting the current data record ptrs back with their
last_dt_rec ptrs.
|
Function
|
set_ptrs_2_next_day
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_ptrs_2_next_day( void )
|
Remarks
|
Calculate the next trading forward into time and update the DATA_REC
current data record ptr dates.
|
Function
|
set_file_rec_numbers
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_file_rec_numbers( void )
|
Remarks
|
Calculate where to start reading the file based on num_of_days_to_output,
days_needed and maybe start_date & last_date info. Will set
num_of_recs_2_read.
|
Function
|
load_the_data_array
|
Include file
|
IND_ENG.H
|
Prototype
|
DATA_REC * load_the_data_array( char *ticker )
|
Remarks
|
Allocate, load and return a DATA_REC array with
num_of_recs_2_read data records.
|
Function
|
cnvt_bond_data_into_decimal
|
Include file
|
IND_ENG.H
|
Prototype
|
void cnvt_bond_data_into_decimal( void )
|
Remarks
|
Convert the open,high,low and close fields of the main DATA_REC array
from T-Bond 1/32's into T-Bond decimal if necessary.
|
Function
|
process_the_data_array
|
Include file
|
IND_ENG.H
|
Prototype
|
void process_the_data_array( void )
|
Remarks
|
Run the process_records against the data arrays.
|
Function
|
calc_next_trading_date
|
Include file
|
IND_ENG.H
|
Prototype
|
float calc_next_trading_date( float last_rec_date )
|
Remarks
|
Convert a given date to the next market day.
|
Function
|
roll_2_tomorrow
|
Include file
|
IND_ENG.H
|
Prototype
|
UINT roll_2_tomorrow( UINT last_rec_julian )
|
Remarks
|
A simple (and stupid) advance to the next market day, holiday checking
is not done.
|
Function
|
set_trade_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_trade_signal_state( int idx , int opinion )
|
Remarks
|
Set and update the trade signal state for output number - idx according
to the opinion.
|
Function
|
update_trade_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void update_trade_signal_state( int idx )
|
Remarks
|
Update the current trade signal for state changes (exp. old state GO_LONG,
new state at exit - LONG).
|
Function
|
set_ind_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_ind_signal_state( int idx , float cur_value , float last_value )
|
Remarks
|
Calculate an indicator trade signal state using as a basis the current
and last indicator values.
|
Function
|
calc_ob_os_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void calc_ob_os_signal_state( int idx ,
float overbought_threshold , float oversold_threshold )
|
Remarks
|
Calculate an indicator trade signal state by evaluating the current
indicator value in relation to overbought and oversold thresholds.
|
Function
|
calc_rev_ob_os_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void calc_rev_ob_os_signal_state( int idx ,
float overbought_threshold , float oversold_threshold )
|
Remarks
|
This is the same as the last routine except this one has reversed
threshold logic to handle flakey thresholds like original Williams' %R.
|
Function
|
set_ob_os_ind_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void set_ob_os_ind_signal_state( int idx , int opinion )
|
Remarks
|
Set and update the indicator trade signal state using as a basis
the indicator value in relation to overbought and oversold thresholds.
|
Function
|
allocate_trd_signal_routine
|
Include file
|
IND_ENG.H
|
Prototype
|
void allocate_trd_signal_routine( void )
|
Remarks
|
Allocate and initialize a user requested trade signal process routine
structure and hook it on to the cur_prc_rec.
|
Function
|
chk_4_user_requested_trd_sig
|
Include file
|
IND_ENG.H
|
Prototype
|
int chk_4_user_requested_trd_sig( float cur_ind , float src_data )
|
Remarks
|
Check the cur_prc_rec's trd_sig_ptr, if a user requested special trade
signal routine is found, run it.
|
Function
|
fe_calc_ob_os_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void fe_calc_ob_os_signal_state( void )
|
Remarks
|
Front end calc_ob_os_signal_state() since function ptrs don't have
prototypes the float arguments get pushed as ints
|
Function
|
fe_set_ind_signal_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void fe_set_ind_signal_state( void )
|
Remarks
|
Front end set_ind_signal_state() since function ptrs don't have prototypes
the float arguments get pushed as ints
|
Function
|
validate_with_str_array_stricmp
|
Include file
|
IND_ENG.H
|
Prototype
|
int validate_with_str_array_stricmp(
char *validate_strs[] , char *target , int cnt )
|
Remarks
|
Normal validate_with_str_array except use stricmp for a case-insensitive
compare between target and validate_strs.
|
Function
|
chk_data_tables
|
Include file
|
IND_ENG.H
|
Prototype
|
void chk_data_tables( void )
|
Remarks
|
This is a run-time check that all the definition tables are the same size.
|
Function
|
process_template_file
|
Include file
|
IND_ENG.H
|
Prototype
|
void process_template_file( char *template_file )
|
Remarks
|
Load and process a report template file into the process_records.
|
Function
|
process_1_template_line
|
Include file
|
IND_ENG.H
|
Prototype
|
void process_1_template_line( char *input_line )
|
Remarks
|
Worker routine to process a single template line into a process_record.
|
Function
|
init_ind_eng_vars
|
Include file
|
IND_ENG.H
|
Prototype
|
void init_ind_eng_vars( void )
|
Remarks
|
Initialize the program global and permanent variables.
|
Function
|
validate_primary_verb
|
Include file
|
IND_ENG.H
|
Prototype
|
void validate_primary_verb( void )
|
Remarks
|
Validate that the first token is a primary verb (or an abbreviation of
one). Will set the GLOBAL var verb_idx to either the matched verb or
max table size if not found.
|
Function
|
chk_if_valid_data_source
|
Include file
|
IND_ENG.H
|
Prototype
|
int chk_if_valid_data_source( int found_data_src )
|
Remarks
|
Check if found data source is valid for this primary verb.
|
Function
|
find_data_source
|
Include file
|
IND_ENG.H
|
Prototype
|
int find_data_source( char *request )
|
Remarks
|
Identify if the user request is a valid data source (or an abbreviation
of one). Also remaps the file constant data source to their special flag
numbers.
|
Function
|
rpt_current_state
|
Include file
|
IND_ENG.H
|
Prototype
|
void rpt_current_state( void )
|
Remarks
|
Do a run-time dump of the current state of all user visible indicator
variables.
|
Function
|
process_paren_assignment
|
Include file
|
IND_ENG.H
|
Prototype
|
void process_paren_assignment( int idx )
|
Remarks
|
Called when a set of parentheses is found in a token str (ie_tokens[ idx ]).
This code identifies which trading system the user is providing
overbought and oversold thresholds for, and then stores them.
Example - threshold_trd_sig( 2000 , -2000 )
|
Table of Contents
Function Index
generated on 22 September 1998 - 12:55:02
© 1998 Tierra del Fuego Ltd.
|