Ir al contenido
← Todos los ejemplos

Ejemplo 21

Indicator by prefix

turn an indicator on for every chart whose symbol starts with

Categoría
Espacio de trabajo: lee o cambia gráficos y paneles
Permisos
workspace.readworkspace.write
Antes de ejecutarlo
a terminal window
Qué hace
CHANGES YOUR WORKSPACE — shows or hides the indicator on
Cómo ejecutarlo
in TTT, open the T0 Editor, open this file, grant workspace.read
Lenguaje
>=0.1.1, <0.2.0
Host
>=0.1.1, <0.2.0
Necesita
workspace >=0.1.1, <0.2.0

Código

// 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(());
}