histogram
Bins raw data automatically and shows the counts with sample size, mean, median and share of positive values.
Examples
Shows the distribution of the changes of the last 200 hourly K-lines.
javascript
function main() {
var r = exchange.GetRecords(PERIOD_H1)
if (!r || r.length < 3) return
r = r.slice(-201)
var rets = r.slice(1).map(function (b, i) { return b.Close / r[i].Close - 1 })
LogStatus({type: "histogram", title: "Hourly change distribution", data: rets,
format: {percent: true, precision: 2}})
}
python
def main():
r = exchange.GetRecords(PERIOD_H1)
if not r or len(r) < 3:
return
r = r[-201:]
rets = [r[i]["Close"] / r[i - 1]["Close"] - 1 for i in range(1, len(r))]
LogStatus({"type": "histogram", "title": "Hourly change distribution", "data": rets,
"format": {"percent": True, "precision": 2}})
rust
fn main() {
let Ok(r) = exchange.GetRecords(None, PERIOD_H1, None) else { return };
if r.len() < 3 { return; }
let r = &r[r.len().saturating_sub(201)..];
let rets: Vec<String> = r.windows(2)
.map(|w| (w[1].Close / w[0].Close - 1.0).to_string())
.collect();
LogStatus!(format!(
r#"{{"type": "histogram", "title": "Hourly change distribution", "data": [{}],
"format": {{"percent": true, "precision": 2}}}}"#,
rets.join(",")
));
}Attributes
| Name | Type | Description |
type | string | Required. Always |
data | numeric array | Required. Raw data, at least 2 numbers. |
bins | number | Number of bins, |
format | object | Format of bin bounds and statistics; see |
color | string | Bar color. By default positive bins use the up color and negative ones the down color. Values: see |
height | number | Height in pixels, |
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
When the data has both signs, 0 falls on a bin boundary, so gains and losses never share a bin.