Quadcode Script

QCS is a language that allows creating custom technical analysis instruments. Currently, the language is based on Lua 5.3 and supports most of the Lua language features.

The script on QCS defines the calculation of the single instrument value using the current security values, historical data and the user input.

Example

 1instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true }
 2
 3period = input (14, "Period", input.integer, 1)
 4
 5input_group {
 6   "Line",
 7   color = input { default = "red", type = input.color },
 8   width = input { default = 1, type = input.line_width}
 9}
10
11ma = sma (close, period)
12
13plot (ma, "SMA", color, width)
instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true }

This line defines the full and short names for the instrument. The full name is used in the add instruments popup. The short name is displayed on the plot. Additionally, this line sets that the instrument will be plotted as a plot overlay. For more information, see instrument.

period = input (14, "Period", input.integer, 1)

Defines a user-settable period that is an integer value not less than 1. For more information, see input.

input_group {
   "Line",
   color = input { default = "red", type = input.color },
   width = input { default = 1, type = input.line_width}
}

Defines an input group for the instrument visuals. For more information, see input_group.

ma = sma (close, period)

This line calculates the simple moving average of the close value.

plot (ma, "SMA", color, width)

This line plots the previously calculated moving average.

For more examples, the source code of the built in library is available: https://github.com/quadcode-tech/quadcodescript-library

Built-in series

open overlayable

Open value of the current candle

close overlayable

Close value of the current candle

high overlayable

High value of the current candle

low overlayable

Low value of the current candle

volume

Volume of the current candle

hml overlayable

high - low

hl2 overlayable

(high + low) / 2

hlc3 overlayable

(high + low + close) / 3 (aka typical price)

ohlc4 overlayable

(open + high + low + close) / 4

hlcc4 overlayable

(high + low + close + close) / 4

tr

max (high - low, high - close [1], close [1] - low) (aka true range)

close_time

Candle closing time (unix time)

open_time

Candle opening time (unix time)

day

Candle opening time (day number in a year)

week_day

Candle opening time (day number in a week)

month

Candle opening time (month)

year

Candle opening time (year)

hour

Candle opening time (hour)

minute

Candle opening time (minute)

second

Candle opening time (second)