gauge
Shows where a value sits in a range on a half-circle dial, with optional threshold colors; for RSI, exposure or risk.
Examples
Shows where the last price sits in the 24-hour high-low range, changing color near the ends.
javascript
function main() {
var r = exchange.GetRecords(PERIOD_H1)
if (!r || r.length < 24) return
var bars = r.slice(-24)
var hi = Math.max.apply(null, bars.map(function (b) { return b.High }))
var lo = Math.min.apply(null, bars.map(function (b) { return b.Low }))
var pos = hi > lo ? (bars[23].Close - lo) / (hi - lo) : 0.5
var levels = [{value: 0, color: "down"}, {value: 0.2, color: "primary"},
{value: 0.8, color: "up"}]
LogStatus({type: "gauge", title: "Position in 24h range", value: pos,
format: {percent: true}, thresholds: levels})
}
python
def main():
r = exchange.GetRecords(PERIOD_H1)
if not r or len(r) < 24:
return
bars = r[-24:]
hi = max(b["High"] for b in bars)
lo = min(b["Low"] for b in bars)
pos = (bars[-1]["Close"] - lo) / (hi - lo) if hi > lo else 0.5
levels = [{"value": 0, "color": "down"}, {"value": 0.2, "color": "primary"},
{"value": 0.8, "color": "up"}]
LogStatus({"type": "gauge", "title": "Position in 24h range", "value": pos,
"format": {"percent": True}, "thresholds": levels})
rust
fn main() {
let Ok(r) = exchange.GetRecords(None, PERIOD_H1, None) else { return };
if r.len() < 24 { return; }
let bars = &r[r.len() - 24..];
let hi = bars.iter().map(|b| b.High).fold(f64::MIN, f64::max);
let lo = bars.iter().map(|b| b.Low).fold(f64::MAX, f64::min);
let pos = if hi > lo { (bars[23].Close - lo) / (hi - lo) } else { 0.5 };
LogStatus!(format!(
r#"{{"type": "gauge", "title": "Position in 24h range", "value": {},
"format": {{"percent": true}},
"thresholds": [{{"value": 0, "color": "down"}}, {{"value": 0.2, "color": "primary"}},
{{"value": 0.8, "color": "up"}}]}}"#,
pos
));
}Attributes
| Name | Type | Description |
type | string | Required. Always |
value | number | Required. Current value. |
min | number | Lower bound. Default |
max | number | Upper bound, must be greater than |
unit | string | Unit. |
format | object | Number format |
color | string | Color when no threshold is reached, default |
thresholds | object array | Thresholds: the color of the highest threshold reached by |
thresholds[].value | number | From this value on |
thresholds[].color | string | Color: |
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
A max not greater than min shows an error card.