Gondola Language

The Gondola Language is a language for analysing stock market data. The language allows you to do a variety of tasks from listing stocks in tables that only match your criteria to creating automated buy/sell paper trade rules. The language is closely modelled after the C programming language, so if you know that language, then you should find Gondola easy and familliar to work with.

Whenever you enter a Gondola expression there are two implicit variables that are always set: the current date and the current stock. For example if you are displaying a Table of stock quotes, you can execute an equation for each stock. If you entered this line:

avg(close, 30)

It would display, for each stock, the average day close value over the last 30 days starting from today. Here the current date would be set to the most recent day you have a quote for and the current stock would be set to the current stock.

You can also enter equations when performing Paper Trading. If you entered the following as a buy rule:

avg(close, 15) > avg(close, 30, -1)

It would only buy the stock when the average day close over the last 15 days was higher than the average day close of over the last 30 days, where the 30 day average would be calculated starting from the previous day and working backwards. So here the current date would be set to whatever date the trade was to be analysed for.

The Gondola language is very type strict. What this means is that each value has a given type, whether it is an integer, real or boolean. This means that the numbers 12 and 12.0 are different, and 1 and true are different. If you get a type mismatch error, you've probably entered an integer number (e.g. 12) instead of a real number (e.g. 12.0).

Gondola Operators

The Gondola language supports the following boolean operators: and, or and not. For example:

It also supports basic arithmetic: +, -, * and /. For example:

The type of returned value of arithmetic operators is the same of the first operand. The following examples explain the behaviour:

And finally it also supports the relational operators: ==, >, >=, <, <= and !=. For example:

Gondola Variables

The Gondola language has full support for variables, which allow you to store, retrieve and manipulate values. When defining a new variable you need to specify whether the variable can change or is constant, the variable type, the name of the variable and optionally the initial value of the variable.

Examples:

Gondola Functions

Absolute Value

The absoluate value function returns the absolute value of the given value. The absolute value is the positive value of a number. For example the absolute value of -12 is 12, and the absolute value of 12 is 12.

abs(VALUE)

Where VALUE is the initial value.

Example:

abs(-28.0)

Returns the absolute value of -28.0 which is 28.0.

Average

The average function averages a series of stock quotes.

avg(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to average. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

avg(open, 15, -1)

Returns the average of the day open value for the current stock for the last 15 days, ending with yesterday.

Bollinger Bands

The bollinger bands are: bol_upper=avg+2sd, bol_lower=avg-2sd .

bol_lower(QUOTE, DAYS[, START_OFFSET])

bol_upper(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to average. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

bol_upper(close, 26, -1)

Returns the bollinger band value of the day close value for the current stock for the last 26 days, ending with yesterday.

The expression bol_lower(close, 26, 0) is the same as bol_lower(close, 26) similarly for open, high and low.

The expression bol_upper(close, 26, 0) is the same as bol_upper(close, 26) similarly for open, high and low.

Correlation

The correlation function returns the correlation between two stock quotes.

corr(SYMBOL, QUOTE, DAYS[, START_OFFSET])

Where SYMBOL is the stock symbol. Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to correlate. Where START_OFFSET is the most recent date to correlate, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

corr("CBA", close, 30, -1)

Returns the correlation of the day close values of this stock and CBA over 30 days ending in yesterday.

Day

The day function returns the current day of the month.

day()

Example:

day()

Returns the current day, which will be 31, if it is the 31st.

Day of Week

The day of week function returns the current day of the week.

dayofweek()

Example:

dayofweek()

Returns the current day of the week, which will be 1, if it is a Sunday.

Day of Year

The day of year function returns the current day of the year.

dayofyear()

Example:

dayofyear()

Returns the current day of the year, which might be 365, if it is New Years Eve.

Exponential Moving Average

The exponential moving average function averages a series of stock quotes according to the following equation: EMA(current) = EMA(previous) + SMOOTHING_CONSTANT * (QUOTE - EMA(previous).

ema(QUOTE, DAYS[, START_OFFSET][, SMOOTHING_CONSTANT])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to average. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc. Where SMOOTHING_CONSTANT is the smoothing constant.

Example:

ema(close, 26, 0.1, -1)

Returns the average of the day close value for the current stock for the last 26 days, ending with yesterday.

The expression ema(close, 26, 0, 0.1) is the same as ema(close, 26) similarly for open, high and low.

The expression ema(close, 26, 0, 0.2) is the same as ema(close, 26, 0.2) similarly for open, high and low.

The expression ema(close, 26, -1, 0.1) is the same as ema(close, 26, -1) similarly for open, high and low.

For

The for function is a looping function that allows you to loop over an expression of code. Typically the loop is tied to a variable, so you need to set the initial value of the variable, a condition where the loop will terminate, and how the variable should change after each loop.

for(INITIAL; CONDITION; LOOP) { COMMAND }

The function will execute the INITIAL expression, then execute the COMMAND expression, and then execute the LOOP expression. It will then execute the CONDITION expression. If the CONDITION expression was FALSE then the function will return. Otherwise it will run the COMMAND expression, then the LOOP expression, then check the CONDITION expression, etc.

Example:

int b = 0

for(int i = 0; i < 10; i = i + 1) {
  b = b + i
}

The above code will sum the numbers 0, 1, 2, ... 9 and store the result in the b variable.

If

The if function allows a selection of which code to be executed.

if(VALUE) { TRUE } else { FALSE }

If the value of the VALUE expression is true, then the TRUE expression will be executed, otherwise the FALSE expression will be.

Example:

if(lag(open, 0) > lag(open, -1)) {
   lag(open, 0)
}
else {
   lag(open, -1)
}

Returns the greater of today and yesterday's day open values.

Lag

The lag function returns a stock quote.

lag(QUOTE[, OFFSET])

Where QUOTE is open, close, low, high or volume. Where OFFSET is the date to retrieve the stock quote, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

lag(high, -5)

Returns the day high value of the current stock, 5 days previous.

The expression lag(close, 0) is the same as lag(close) and they can both be abbreviated to close; similarly for open, high and low.

Minimum

The minimum function finds the minimum of a series of stock quotes.

min(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to search. Where START_OFFSET is the most recent date to search, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

min(volume, 15, -1)

Returns the minimum volume of trade for the current stock for the last 15 days, ending with yesterday.

Maximum

The maximum function finds the maximum of a series of stock quotes.

max(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to search. Where START_OFFSET is the most recent date to search, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

max(volume, 15, -1)

Returns the maximum volume of trade for the current stock for the last 15 days, ending with yesterday.

Moving Average Convergence Divergence

The MACD is: MACD = 26 days EMA - 12 days EMA.

macd(QUOTE[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

macd(close, -1)

Returns the macd value of the day close value for the current stock ending with yesterday.

The expression macd(close, 0) is the same as macd(close) similarly for open, high and low.

The expression macd(close, 0) is the same as ema(close,26,0,0.1)-ema(close,12,0,0.1) similarly for open, high and low.

Momentum

The momentum is: momentum(now)=quote(now)-quote(period deleyed).

momentum(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to delay. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

momentum(close, 26, -1)

Returns the momentum value of the day close value for the current stock for the last 26 days, ending with yesterday.

The expression momentum(close, 26, 0) is the same as momentum(close, 26) similarly for open, high and low.

Month

The month function returns the current month.

month()

Example:

month()

Returns the current month, which will be 8, if it is August.

On Balance Volume

The OBV is the sum of volumes in the period, counted as positive if close is greater than open or as negative if open is greater then close.

obv(DAYS[, START_OFFSET[, INITIAL_VALUE]])

Where DAYS is the number of days to count over. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc. Where INITIAL_VALUE is the initial value which counting from

Example:

obv(200, -1, 50000)

Returns the obv value counted over the last 200 days, ending with yesterday, starting with value 50000.

The expression obv(200) is the same as obv(200, 0, 50000).

Percent

The percent function returns the given percent of the given value.

percent(VALUE, PERCENT)

Where VALUE is the initial value and PERCENT is the ratio to return.

Example:

percent(200, 10)

Returns 10% of 200 which is 20.

Relative Strength Index

This function calculates the Relative Strength Index (RSI) of the current stock.

rsi([PERIOD[, START_OFFSET]])

Where PERIOD is the period to apply the RSI. Where START_OFFSET is the most recent date to calculate, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

rsi()

Returns the RSI of the current stock.

Square Root

The square root function returns the square root of the given value.

sqrt(VALUE)

Where VALUE is the initial value.

Example:

sqrt(144)

Returns the square root of 144 which is 12.

Standard Deviation

sd(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to average. Where START_OFFSET is the most recent date to average, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

sd(close, 26, -1)

Returns the standard deviation value of the day close value for the current stock for the last 26 days, ending with yesterday.

The expression sd(close, 26, 0) is the same as sd(close, 26) similarly for open, high and low.

Sum

The sum function sums a series of stock quotes.

sum(QUOTE, DAYS[, START_OFFSET])

Where QUOTE is open, close, low, high or volume. Where DAYS is the number of days to sum. Where START_OFFSET is the most recent date to sum, 0 means the current trading date, -1 means the previous trading date, etc.

Example:

sum(open, 15, -1)

Returns the sum of the day open value for the current stock for the last 15 days, ending with yesterday.

While

The while function is a looping function that allows you to loop over an expression of code. The loop contains an expression that will be executed until a specific condition is not met.

while(CONDITION) { COMMAND }

The function will execute the COMMAND expression until the CONDITION is not met. If the CONDITION is never met, the loop will not be entered.

Example:

int sum = 1

while(sum < 100) {
  sum = sum + 1
}

The above code will keep increment the value of sum until it is equal to 100.

Year

The year function returns the current year.

year()

Example:

year()

Returns the current year, which will be 2004, if it is 2004.