chart
Draws line, bar or area charts with several series, a right axis and buy/sell marks; use Chart for more options.
Examples
Close prices as a line with volume bars on the right axis, and a mark at the highest close.
javascript
function main() {
var r = exchange.GetRecords(PERIOD_H1)
if (!r || r.length < 48) return
r = r.slice(-48)
var top = r.reduce(function (a, b) { return b.Close > a.Close ? b : a })
LogStatus({
type: "chart", title: "Last 48 hours",
x: r.map(function (b) { return b.Time }),
series: [
{name: "Close", data: r.map(function (b) { return b.Close })},
{name: "Volume", kind: "bar", axis: "right", color: "muted",
data: r.map(function (b) { return b.Volume })}
],
marks: [{x: top.Time, text: "High", color: "up"}]
})
}
python
def main():
r = exchange.GetRecords(PERIOD_H1)
if not r or len(r) < 48:
return
r = r[-48:]
top = max(r, key=lambda b: b["Close"])
LogStatus({
"type": "chart", "title": "Last 48 hours",
"x": [b["Time"] for b in r],
"series": [
{"name": "Close", "data": [b["Close"] for b in r]},
{"name": "Volume", "kind": "bar", "axis": "right", "color": "muted",
"data": [b["Volume"] for b in r]}
],
"marks": [{"x": top["Time"], "text": "High", "color": "up"}]
})
rust
fn join<T: ToString>(v: impl Iterator<Item = T>) -> String {
v.map(|x| x.to_string()).collect::<Vec<_>>().join(",")
}
fn main() {
let Ok(r) = exchange.GetRecords(None, PERIOD_H1, None) else { return };
if r.len() < 48 { return; }
let r = &r[r.len() - 48..];
let top = r.iter().fold(&r[0], |a, b| if b.Close > a.Close { b } else { a });
LogStatus!(format!(
r#"{{"type": "chart", "title": "Last 48 hours", "x": [{}], "series": [
{{"name": "Close", "data": [{}]}},
{{"name": "Volume", "kind": "bar", "axis": "right", "color": "muted", "data": [{}]}}],
"marks": [{{"x": {}, "text": "High", "color": "up"}}]}}"#,
join(r.iter().map(|b| b.Time)),
join(r.iter().map(|b| b.Close)),
join(r.iter().map(|b| b.Volume)),
top.Time
));
}Attributes
| Name | Type | Description |
type | string | Required. Always |
series | object array | Required. Data series. |
series[].data | numeric array | Required. One value per |
series[].name | string | Legend name. |
series[].kind | string | Type of this series, overriding |
series[].color | string | Series color, assigned in order by default. Values: see |
series[].axis | string |
|
kind | string |
|
x | string array / numeric array | X-axis values. A time axis when all are millisecond timestamps; indexes when omitted. |
marks | object array | Marks such as buy/sell or rebalance points. |
marks[].x | string / number | Required. A value of |
marks[].y | number | Y value. Defaults to the first series at that point. |
marks[].text | string | Mark label. |
marks[].color | string |
|
stacked | bool | Stack the series. Default |
height | number | Height in pixels, |
format | object | Left-axis number format, default |
rightFormat | object | Right-axis number format. Defaults to |
title | string | Title shown at the top left of the component. |
id | string | Stable identifier. Set it when the number or order of components changes, so refreshes do not rebuild the component. |
span | number | Number of columns it spans in the enclosing |
See Also
Remarks
Each series holds at most 5000 points; more shows an error card. A legend is shown for several series; drag on the chart to zoom into an x range.