본문으로 건너뛰기
← 모든 예제

예제 21

Indicator by prefix

turn an indicator on for every chart whose symbol starts with

분류
Workspace: 차트와 패널을 읽거나 변경
권한
workspace.readworkspace.write
실행하기 전에
a terminal window
하는 일
CHANGES YOUR WORKSPACE — shows or hides the indicator on
실행 방법
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: turn an indicator on for every chart whose symbol starts with
// a prefix, and off for the others — then read each chart back, so what
// is printed is what the terminal holds, not what the program asked for.
// Category: workspace
// Permissions: workspace.read, workspace.write
// Preconditions: a terminal window
// Side effects: CHANGES YOUR WORKSPACE — shows or hides the indicator on
// every open chart.
// Run: in TTT, open the T0 Editor, open this file, grant workspace.read
// and workspace.write, Run.

lang ">=0.1.1, <0.2.0";
host "ttt" ">=0.1.1, <0.2.0";
requires "workspace" ">=0.1.1, <0.2.0";
import std.text;
import std.list;

fn main() -> Result<Unit, Error> {
    let prefix = "BTC";
    let indicator = "EMA";
    for c in workspace.charts() {
        let wanted = text.starts_with(c.symbol, prefix);
        workspace.set_indicator(c.chart, indicator, wanted)?;
        let drawn = list.contains(workspace.indicators(c.chart)?, "Exponential Moving Average");
        print(c.symbol + " " + c.timeframe + ": " + indicator + (if drawn { " on" } else { " off" }));
    }
    return Ok(());
}