本文へ移動
← すべてのサンプル

サンプル 20

All charts to timeframe

put every open chart on one timeframe, and say which ones

カテゴリ
Workspace:チャートやパネルを読む・変更する
権限
workspace.readworkspace.write
実行する前に
a terminal window
何をするか
CHANGES YOUR WORKSPACE — sets the timeframe of every open
実行方法
in TTT, open the T0 Editor, open this file, grant workspace.read
言語
>=0.1.1, <0.2.0
ホスト
>=0.1.1, <0.2.0
必要なもの
workspace >=0.1.1, <0.2.0

ソース

// Purpose: put every open chart on one timeframe, and say which ones
// were already there. A refused timeframe stops the program before it
// touches a chart.
// Category: workspace
// Permissions: workspace.read, workspace.write
// Preconditions: a terminal window
// Side effects: CHANGES YOUR WORKSPACE — sets the timeframe of every open
// chart.
// Run: in TTT, open the T0 Editor, open this file, grant workspace.read
// and workspace.write, Run. Change `timeframe` (5m, 1h, 1D ...).

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.1, <0.2.0";
requires "workspace" ">=0.1.1, <0.2.0";

fn main() -> Result<Unit, Error> {
    let timeframe = "15m";
    let mut changed = 0;
    for c in workspace.charts() {
        if c.timeframe == timeframe {
            print(c.symbol + ": already " + timeframe);
        } else {
            workspace.set_timeframe(c.chart, timeframe)?;
            changed = changed + 1;
            print(c.symbol + ": " + c.timeframe + " -> " + timeframe);
        }
    }
    print(to_string(changed) + " chart(s) changed");
    return Ok(());
}