Example
instrument { name = "Simple Moving Average", short_name = "SMA", overlay = true }
period = input (14, "Period", input.integer, 1)
input_group {
"Line",
color = input { default = "red", type = input.color },
width = input { default = 1, type = input.line_width}
}
ma = sma (close, period)
plot (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)
Built-in functions:
For convenience and performance reasons, QCS has a wide range of built-in functions.
Averages:
alma
ema
hma
rma
sma
ssma
tma
vidya
vwma
wma
User Input
input
input_group
Plots
fill
fill_area
hline
plot
plot_candle
plot_shape
rect
Math
abs
acos
asin
atan
ceil
change
correlation
cos
deg
exp
floor
linreg
log
mad
max
median
min
modf
percentile_linear_interpolation
percentile_nearest_rank
rad
round
sin
sqrt
stdev
sum
tan
Oscillators
cci
cmo
stochastic
Momentum Instruments
roc
rsi
Miscellaneous
advise
assert
bars_since
bars_since_highest
bars_since_lowest
conditional
date
drop_plot_value
error
fixnan
get_name
get_value
highest
iff
index_range
instrument
is_series
is_value
isnan
lower_prime
lowest
make_series
na
nz
prime_bands
print
rgb
rgba
sar
upper_prime
value_when
version
Security
get_ticker_id:
security
State Variables
current_bar_id:
current_ticker_id
is_daily
is_dwm
is_intraday
is_intrahour
is_monthly
is_weekly
resolution
runtime_version
Built-in Types