Overbasic – Database

Table of Contents

DATABASE keyword is used to access data (both historical and real time) of a specific instrument/resolution. To access data of the indicator/trading-system reference chart it is NOT necessary to declare any database. However, to access data of different instruments, or to access data of the reference instrument with a different resolution, it is necessary to declare a database.

Syntax #

Database <database name> ("<instrument name>", "<resolution type>", <resolution units>, "<quote type>")

To access data series of an instrument/resolution other than reference chart, it is necessary to declare a database. A Database is defined by DATABASE keyword and the following attributes:

Database Name: defines database unique name. You can define database name as you like. You will use it within the script to access the database.

Instrument Name: specifies the exact instrument name to access. The name is the one defined in the Instruments Tab of Overcharts main window. To avoid errors, we recommend you set the instrument name using the value list. If the instrument you want to access is the same as the reference chart, leave this field blank.

Resolution Type: specifies data series resolution. T = Tick, C = Contract (volume bar), P = Point (range bar), S = Second, MIN = Minute, H = Hour, SES = Session, D = Day, W = Week, M = Month, Q = Quarter, Y = Year.

Resolution Units: specifies resolution units. For example, if Resolution Type is minute and Resolution Units is 5, database resolution will be 5 minutes.

Quote Type: specifies quote type: T = Trade, B = Bid, A = Ask.

Databases must be defined at script level, that is, externally to all functions. We recommend you define all Databases at the beginning of the script.

DBexp function #

Once a database is declared, you can access the data using DBEXP function:

My.Data.DBEXP(<expression>, <database name>, [<value by date>])

DBEXP function allows you to calculate any expression using database data.

DBEXP arguments are:

<expression>: any expression

<database name>: database name to use to calculate <expression>

<value by date>: (optional, default True). If TRUE, current bar in the external database is determined based on timestamp of reference chart current bar. If FALSE, current bar in the external database matches the reference chart current bar number. It is clear that if the two data series are not perfectly synchronized, or if they have different resolutions, setting this argument to FALSE would produce incorrect results. We recommend you always set this argument to TRUE, unless you have special needs.

Usage #

Example:

Database AppleMin5 ("Apple", "MIN", 5, "T")

'If the instrument is the same as reference chart, you can leave the instrument name blank:
Database ThisDay1 ("", "D", 1, "T")

Function Main()
   ...
   If ((My.Data.DBexp(Close > Open, ThisDay1) = True) Then
      ...
   EndIf
   ...
   Dim MyValue As Numeric = My.Data.DBexp((High + Low) / 2, AppleMin5)
   ...
EndFunction

To make database declaration dynamic, you can use a database Property instead of declaring the database within the script. In this way, you will set the database in the indicator/trading-system properties window from time to time:

Property DB1 As Database
EndProperty

Function Main()
   ...
   If ((My.Data.DBexp(Close > Open, DB1) = True) Then
      ...
   EndIf
   ...
EndFunction