Docs·TapeScript

Inputs & directives

TapeScript directives — @name for the title, @input for settings in the Inputs tab, @interval for the onInterval period and @history to replay stored data.

Directives are comment lines that start with // @. Place them at the top of the file.

JavaScript
// @name     Absorption Watch
// @input    minSize: float = 5 "Min print size"
// @input    sound: bool = true "Sound alert"
// @interval 250ms

@name

JavaScript
// @name Absorption Watch

Script title, up to 80 characters. Samples are listed by this title. Your own scripts are listed, released and referenced by their file name.

@input

JavaScript
// @input  name: type = default "Label"

Declares a setting shown in the Inputs tab. Read it in code as input.<name>.

JavaScript
// @input mult: float = 6 "Size vs average (x)"

function onTrade(price, size) {
  if (size >= avg.mean * input.mult) { … }
}
TypeDefault exampleValue
float= 1.5Number
int= 200Whole number
bool= truetrue or false
string= "fill"String
color= "#0ECB81"Color string for series or marker
  • The label is optional. Without it, the Inputs tab shows the name.
  • Each name can be used once per script.
  • Changing a value restarts every running instance of the script, on every chart, with the new value.
  • Values are saved on this computer per script name. The file keeps only the defaults.

@interval

JavaScript
// @interval 250ms
// @interval 1s

Enables onInterval and sets its period in ms or s. Allowed range: 50 ms to 60 s. Without @interval, onInterval is not called.

@history

JavaScript
// @history 30m
// @history 2h

Before going live, the script runs over the stored book and trades of this period (or the venue's past trades where nothing was recorded), so its lines, markers and zones cover the recent past too. Units: m or h. Allowed range: 1 minute to 4 hours. Without @history, the script starts from the moment you run it.

See History for what the script receives during the replay.

@telegram

JavaScript
// @telegram 123456789:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw
// @telegram 123456789:AAHdqTcvCH1vGWJxfSeofSAs0K5PALDsaw -1001234567890

Sends this script's alerts to a Telegram bot: the bot token from @BotFather, then an optional chat ID. Each script can name a different bot; a script without this line sends nothing. A wrong token or chat ID does not stop the script: the Console says what is wrong and nothing is sent. See Telegram.

Errors

MessageCause
Bad @input — use: name: float = 1 "Label"Wrong @input format
Duplicate @input 'name'Same input name twice
Bad @interval — use: 250ms or 1sWrong @interval format
Bad @history — use: 30m or 2hWrong @history format