← すべてのサンプル
サンプル 30
Prior day levels
yesterday's high, low and close as levels on the chart, from the daily candles.
- カテゴリ
- Workspace:チャートやパネルを読む・変更する
- 権限
- market.readworkspace.readworkspace.write
- 実行する前に
- a terminal window with a chart open
- 何をするか
- DRAWS three horizontal lines on the active chart, named "prior_day". Running it again replaces them.
- 実行方法
- grant market.read, workspace.read and workspace.write in the T0 Editor, Run.
- 言語
>=0.1.1, <0.2.0- ホスト
>=0.1.6, <0.2.0- 必要なもの
- market >=0.1.2, <0.2.0workspace >=0.1.0, <0.2.0plot >=0.1.0, <0.2.0
ソース
// Purpose: yesterday's high, low and close as levels on the chart, from the daily candles. // Category: workspace // Permissions: market.read, workspace.read, workspace.write // Preconditions: a terminal window with a chart open // Side effects: DRAWS three horizontal lines on the active chart, named "prior_day". Running it again replaces them. // Run: grant market.read, workspace.read and workspace.write in the T0 Editor, Run. lang ">=0.1.1, <0.2.0"; host "ttt" ">=0.1.6, <0.2.0"; requires "market" ">=0.1.2, <0.2.0"; requires "workspace" ">=0.1.0, <0.2.0"; requires "plot" ">=0.1.0, <0.2.0"; const OWNER: String = "prior_day"; fn main() -> Result<Unit, Error> { let chart = workspace.active_chart().expect("no chart is open"); // Two closed daily candles: the day before yesterday is ignored, the last closed one is yesterday. let days = market.chart_candles(chart.symbol, "1D", 1)?; let yesterday = days.last().expect("the backend has no closed daily candle for this symbol"); plot.clear(chart.chart, OWNER)?; plot.level(chart.chart, OWNER, yesterday.high, "prior day high", "red")?; plot.level(chart.chart, OWNER, yesterday.low, "prior day low", "green")?; plot.level(chart.chart, OWNER, yesterday.close, "prior day close", "gray")?; print(chart.symbol + ": high " + to_string(yesterday.high) + ", low " + to_string(yesterday.low) + ", close " + to_string(yesterday.close)); return Ok(()); }