January 29, 2015
Importing auxilliary data into AmiBroker database
AmiBroker database structure offers the following fields: Open, High, Low, Close, Volume, OpenInt, Aux1, Aux2. The last two fields, i.e. Aux1 and Aux2 are meant for storing any custom historical data-arrays we may need.
Pretty often, we already have quotations data present in the database and we just want to put some extra data into auxiliary fields. To combine existing data with imported data, we can need to use hybrid mode. In the Import Wizard just add this command in “Additional commands’ field.
# This example assumes that file has format: # Symbol, Year-Month-Day, auxiliary_data1, auxiliary_data2 $FORMAT Name, Date_YMD, Aux1, Aux2 $HYBRID 1 $ALLOWNEG 1
Hybrid mode works so that with each imported record it looks for matching record in the database and it combines existing data with data being imported. If OHLC prices are not provided in the imported file you need to specify $ALLOWNEG 1 option. Otherwise you would get error messages about missing close price.
Auxiliary data fields can then be read using simply Aux1 and Aux2 identifiers:
Plot( Aux1, "Aux1", colorRed )
However – if two additional fields are not enough for our purposes, we can also import quotes into some synthetic tickers and have another set of OHLC, V, OI, Aux1 and Aux2 fields available for importing. Synthetic ticker in this context means just a custom symbol name that’s used just for storing such extra data. So – instead of importing additional arrays into IBM ticker or AAPL ticker, we could use for example IBM_extra and AAPL_extra symbols and their fields.
Using such common naming pattern (i.e. identical ‘_extra’ suffix with the original ticker name) will be useful, because later on to access data from the selected field we could use just the following AFL call:
myVal = Foreign( Name() +"_extra", "C")
and this line will read value from Close field of the respective ‘extra’ ticker as we select IBM or AAPL.
An alternative way to store and handle several custom arrays would be to use SQL database, then we could use ODBC plugin to read such data. The documentation of ODBC plugin is available at:
Filed by Tomasz Janeczko at 6:45 pm under Data
Comments Off on Importing auxilliary data into AmiBroker database