settings
The settings dialog: tabs, sections, rows, notes, checks, presets, migrations (ChartDeck extra). Its tabs: your tabs (else Inputs), Colors, Style, Labels & text, Visibility.
#Functions
#settings.convertedfunction
Migration: saved numbers are converted (value x multiply + add).
settings.converted(name: const string, since: const int, { multiply?: const float = 1, add?: const float = 0 })| Parameter | Type | Description |
|---|---|---|
name | const string | The name. |
since | const int | The since. |
multiply | const floatdefault 1 | The factor. |
add | const floatdefault 0 | Added after the factor. |
Example
const len = input.float(1.5, "Hours")
settings.converted("len", 2, { multiply: 1.0 / 60 })Since ChartScript 1
#settings.defaultsfunction
Script-wide style defaults (text size, font, weight, line width, dash) under every style of the script. The Labels & text size switch of the settings dialog scales them.
settings.defaults(values: const T, …)| Parameter | Type | Description |
|---|---|---|
values | const T | property: value pairs in an options object. |
Example
settings.defaults({ size: size.pt(10), font: font.mono })Since ChartScript 1
#settings.end_rowfunction
Ends the current row.
settings.end_row()Example
settings.row("r", "Pair")
const a = input.int(1, "A")
settings.end_row()Since ChartScript 1
#settings.notefunction
A plain-text help block between inputs.
settings.note(text: const string, { kind?: const string = "info" })| Parameter | Type | Description |
|---|---|---|
text | const string | The note (plain text, no links). |
kind | const stringdefault "info" | "info" or "warning". |
Example
settings.note("Lengths are in bars of the chart timeframe.")Since ChartScript 1
#settings.presetfunction
An author preset: named input values the user can apply in one click (listed above the user's templates).
settings.preset(name: const string, description?: const string = "", tf?: const string = "", default?: const bool = false, values: const T, …)| Parameter | Type | Description |
|---|---|---|
name | const string | The preset name. |
description | const stringdefault "" | One line shown under the name. |
tf | const stringdefault "" | Timeframes it suits ("m1-15", the Visibility encoding). |
default | const booldefault false | Apply automatically to a fresh instance on a matching timeframe. |
values | const T | input: value pairs in an options object, by the input's variable name ({ len: 9 }). |
Example
const len = input.int(20, "Length")
settings.preset("Scalping", { description: "Short lookback", len: 9 })Since ChartScript 1
#settings.preset_stylefunction
The style part of a preset: property values for one style.
settings.preset_style(name: const string, look: const string, values: const T, …)| Parameter | Type | Description |
|---|---|---|
name | const string | The name. |
look | const string | The style (made with style.*). |
values | const T | property: value pairs in an options object. |
Example
const lv = style.line("Levels", { width: 2 })
settings.preset_style("Clean", lv, { width: 1 })Since ChartScript 1
#settings.remapfunction
Migration: saved option values change (old1, new1, old2, new2 ...).
settings.remap(name: const string, since: const int, pairs: const T, …)| Parameter | Type | Description |
|---|---|---|
name | const string | The name. |
since | const int | The since. |
pairs | const T | Old value, new value, ... |
Example
const mode = input.string("Fast", "Mode", { options: ["Fast", "Slow"] })
settings.remap("mode", 3, "Quick", "Fast")Since ChartScript 1
#settings.renamedfunction
Migration: the input name was "was" before script version since; saved values move to the new name.
settings.renamed(name: const string, was: const string, since: const int)| Parameter | Type | Description |
|---|---|---|
name | const string | The input's variable name now. |
was | const string | Its name before. |
since | const int | The script version that renamed it. |
Example
const len = input.int(20, "Length")
settings.renamed("len", { was: "lookback", since: 4 })Since ChartScript 1
#settings.renamed_outputfunction
Migration: an output or style id changed; saved style overrides move to it.
settings.renamed_output(id: const string, was: const string, since: const int)| Parameter | Type | Description |
|---|---|---|
id | const string | The output or style id now (p_..., y_...). |
was | const string | The id before. |
since | const int | The since. |
Example
plot(close, "Close")
settings.renamed_output("p_Close", { was: "p_Last", since: 2 })Since ChartScript 1
#settings.retiredfunction
Migration: the input was removed in this version; saved values are kept for a while, then dropped.
settings.retired(name: const string, since: const int)| Parameter | Type | Description |
|---|---|---|
name | const string | The name. |
since | const int | The since. |
Example
settings.retired("oldSmoothing", 5)Since ChartScript 1
#settings.rowfunction
Starts a labeled row: the next inputs share it, side by side (until settings.end_row, a row or a section). The same as giving the inputs one inline text.
settings.row(id: const string, { title?: const string = "", visible_if?: simple bool = true })| Parameter | Type | Description |
|---|---|---|
id | const string | A stable id (letters, digits, _). |
title | const stringdefault "" | The name shown in the settings, legend and data window. |
visible_if | simple booldefault true | The visible if. |
Example
settings.row("poc", "POC")
const showPoc = input.bool(true, "Show")
const pocColor = input.color(color.accent, "Colour")
settings.end_row()Since ChartScript 1
#settings.sectionfunction
Starts a section of the current tab, with reset, a "changed" count and help. The inputs after it go in this section, and its color inputs are listed under the same title on the Colors tab. A tab with 6 or more sections (or 30 or more inputs) gets a section list beside the inputs.
settings.section(id: const string, title: const string, { collapsed?: const bool = false, help?: const string = "", visible_if?: simple bool = true, enabled_if?: simple bool = true })| Parameter | Type | Description |
|---|---|---|
id | const string | A stable id (letters, digits, _). |
title | const string | The name shown in the settings, legend and data window. |
collapsed | const booldefault false | true: closed until the user opens it. |
help | const stringdefault "" | Help text shown under the heading. |
visible_if | simple booldefault true | The visible if. |
enabled_if | simple booldefault true | The enabled if. |
Example
settings.section("gen", "General")
const len = input.int(20, "Length")
settings.section("look", "Colors", { collapsed: true })
const lineColor = input.color(color.accent, "Line", { role: "accent" })Since ChartScript 1
#settings.tabfunction
Starts an author tab of the settings dialog (your tabs replace Inputs and come before Colors, Style, Labels & text and Visibility; at most 8). The inputs after it go in this tab.
settings.tab(id: const string, title: const string, { icon?: const string = "", visible_if?: simple bool = true })| Parameter | Type | Description |
|---|---|---|
id | const string | A stable id (letters, digits, _). |
title | const string | The name shown in the settings, legend and data window. |
icon | const stringdefault "" | One of the icon.* constants. |
visible_if | simple booldefault true | The visible if. |
Example
settings.tab("levels", "Levels", { icon: icon.layers })
const len = input.int(20, "Length")Since ChartScript 1
#settings.validatefunction
A check across inputs, shown in the panel while the user types; "error" disables OK until it passes.
settings.validate(cond: simple bool, message: const string, { on?: const T = na, severity?: const string = "error" })| Parameter | Type | Description |
|---|---|---|
cond | simple bool | The condition that must hold (a settings condition). |
message | const string | The message shown when it fails. |
on | const Tdefault na | The inputs the message is shown under ([a, b]). |
severity | const stringdefault "error" | The severity. |
Example
const lo = input.int(20, "Low")
const hi = input.int(80, "High")
settings.validate(lo < hi, "Low must be below High", { on: [lo, hi] })Since ChartScript 1