built in series
You can consider the series as a range of data, predefined or generated in the real time according to the price behavior of an asset. These data sets are provided by the platform, and you can use them, depending on the purpose of your script indicator.
Operations with Series
The series, representing different ranges of data, support basic mathematical operations in order to get more values, needed for the script indicators. The simplest example is the operation (open+close)/2,
where the returned value is the series, containing the value of the opening and closing prices sum, divided by 2.
More operations, which are supported by QCS, are presented in the table below:
Operator | Operator's Definition | Left-Hand Side (Value before the Operator) | Right-Hand Side (Value after the Operator) | Result | Example |
---|---|---|---|---|---|
+ | Addition |
|
|
| high + low |
- | Subtraction |
|
|
| high - low |
* | Multiplication |
|
|
| high * 2 |
/ | Division |
|
|
| low / 2 |
^ | Exponentiation (Power Operator) |
|
|
| close ^ 2 |
< | Less than |
|
|
| high < low |
\> | Greater than |
|
|
| high > low |
<= | Less than of equal |
|
|
| high <= low |
\>= | Greater than or equal |
|
|
| high => low |
== | Equal |
|
|
| high == low |
~= | Not equal (inequality operator) |
|
|
| high ~= low |
- | Negation |
|
| negative_open = -open |
Due to Lua limitations, it is not possible to compare series
and a value directly. In this case, you can use the get_value
function. The same restriction applies when using the series as a condition.
Example:
if get_value(open) > 10 then
print ("Hooray!")
end
Series Types
There are several types of series, based on the data they aggregate. The most common are:
- Price series;
- Time series;
- Volume series.
Price Series
The series, which provide the range of price data.
open
- View: overlayable.
- Purpose: the opening price of the current candle.
- Type: series float.
- Example:
instrument { name = "Open Price Indicator", overlay = true }
opening_price = open
plot(opening_price, title="Open Price", color=color.red, linewidth=2)
close
- View: overlayable.
- Purpose: the closing price of the current candle.
- Type: series float.
- Example:
instrument { name = "Close Price Indicator", overlay = true }
closing_price = close
plot(closing_price, title="Close Price", color=color.green, linewidth=2)
high
- View: overlayable.
- Purpose: the highest price of the current candle.
- Type: series float.
- Example:
instrument { name = "Highest Price Indicator", overlay = true }
highest_price = high
plot(highest_price, title="Highest Price", color=color.green, linewidth=2)
low
- View: overlayable.
- Purpose: the lowest price of the current candle.
- Type: series float.
- Example:
instrument { name = "Lowest Price Indicator", overlay = true }
lowest_price = low
plot(lowest_price, title="Lowest Price", color=color.red, linewidth=2)
hml
- View: overlayable.
- Purpose: the highest price minus the lowest price of the current candle.
- Type: series float.
- Formula:
high - low
- Example:
instrument { name = "HML Levels", overlay = true }
high_level = high
low_level = low
diff = (high - low)
plot(diff, title="Diff", color=color.blue, linewidth=2)
hl2
- View: overlayable.
- Purpose: the highest price plus the lowest price of the current candle divided by 2.
- Type: series float.
- Formula:
(high + low) / 2
- Example:
instrument { name = "HL Levels", overlay = true }
high_level = high
low_level = low
mid_level = (high + low) / 2
plot(mid_level, title="Mid", color=color.blue, linewidth=2)
hlc3
- View: overlayable.
- Purpose: the highest price plus the lowest price plus the closing price of the current candle divided by 3.
- Type: series float.
- Formula:
(high + low + close) / 3
- Example:
instrument { name = "HLC3 Indicator", overlay = true }
high_level = high
low_level = low
closing_price = close
hlc3 = (high + low + close) / 3
plot(hlc3, title="HLC3", color=color.blue, linewidth=2)
ohlc4
- View: overlayable.
- Purpose: the sum of all main price values of the candle, divided by 4.
- Type: series float.
- Formula:
(open + high + low + close) / 4
- Example:
instrument { name = "OHLC4 Indicator", overlay = true }
opening_price = open
high_level = high
low_level = low
closing_price = close
ohlc4 = (open + high + low + close) / 4
plot(ohlc4, title="OHLC4", color=color.blue, linewidth=2)
hlcc4
- View: overlayable.
- Purpose: the sum of the highest and lowest price values of the candle plus the closing price of the candle, which is given the double weight in the calculation, divided y 4.
- Type: series float.
- Formula:
(high + low + close + close) / 4
- Example:
instrument { name = "HLCC4 Indicator", overlay = true }
high_level = high
low_level = low
closing_price = close
hlcc4 = (high + low + close + close) / 4
plot(hlcc4, title="HLCC4", color=color.blue, linewidth=2)
tr
- View: overlayable.
- Purpose: the true range series, taking into calculation the difference between the highest and the lowest values of the candle, the difference between the highest and lowest values of the current candle and the closing price of the previous candle.
- Type: series float.
- Formula:
max (high - low, high - close [1], close [1] - low)
- Example:
instrument { name = "True Range Indicator", overlay = false }
high_level = high
low_level = low
closing_price = close
tr = max(high - low, high - close [1], close [1] - low)
plot(tr, title="True Range", color=color.orange, linewidth=2)
Time Series
The series, which provide the timeframe data.
close_time
- View: non-overlayable.
- Purpose: the closing time of the candle (UNIX time).
- Type: series int.
- Example:
instrument { name = "Close Time Indicator", overlay = false }
candle_close_time = close_time
plot(candle_close_time, title="Close Time", color=color.yellow, linewidth=2)
open_time
- View: non-overlayable.
- Purpose: the closing time of the candle (UNIX time).
- Type: series int.
- Example:
instrument { name = "Open Time Indicator", overlay = false }
candle_open_time = open_time
plot(candle_open_time, title="Open Time", color=color.blue, linewidth=2)
day
- View: non-overlayable.
- Purpose: the opening time of the candle (day number in a year).
- Type: series int.
- Example:
instrument { name = "Day Indicator", overlay = false }
current_day = day
plot(current_day, title="Day", color=color.green, linewidth=2)
week_day
- View: non-overlayable.
- Purpose: the opening time of the candle (day number in a week).
- Type: series int.
- Example:
instrument { name = "Week Day Indicator", overlay = false }
week_day = week_day
plot(week_day, title="Week Day", color=color.green, linewidth=2)
month
- View: non-overlayable.
- Purpose: the opening time of the candle (month).
- Type: series int.
- Example:
instrument { name = "Month Indicator", overlay = false }
current_month = month
plot(current_month, title="Month", color=color.green, linewidth=2)
year
- View: non-overlayable.
- Purpose: the opening time of the candle (year).
- Type: series int.
- Example:
instrument { name = "Year Indicator", overlay = false }
current_year = year
plot(current_year, title="Year", color=color.blue, linewidth=2)
hour
- View: non-overlayable.
- Purpose: the opening time of the candle (hour).
- Type: series int.
- Example:
instrument { name = "Hour Indicator", overlay = false }
current_hour = hour
plot(current_hour, title="Hour", color=color.blue, linewidth=2)
minute
- View: non-overlayable.
- Purpose: the opening time of the candle (minute).
- Type: series int.
- Example:
instrument { name = "Minute Indicator", overlay = false }
current_minute = minute
plot(current_minute, title="Minute", color=color.blue, linewidth=2)
second
- View: non-overlayable.
- Purpose: the opening time of the candle (second).
- Type: series int.
- Example:
instrument { name = "Second Indicator", overlay = false }
current_second = second
plot(current_second, title="Second", color=color.blue, linewidth=2)
Volume Series
The series, which provides the volume data.
volume
- View: non-overlayable.
- Purpose: the traded volume of the current candle.
- Type: series float.
- Example:
instrument { name = "Volume Indicator", overlay = false }
current_volume = volume
plot(current_volume, title="Volume", color=color.green, linewidth=2, style=plot.style_points)