Stops the script with an error message. Use it to reject inputs or states the script cannot handle.
runtime.error(message) halts the script on the bar where it runs and reports message as the error, the same way a built-in failure does. Nothing after the call runs, on this bar or on later ones.
Use it as a guard: check an input, the timeframe or a data condition at the top of the script, and stop with a message that tells the user what to change. Wrap the call in an if, since an unconditional runtime.error stops the script on the first bar.
Syntax
runtime.error(message: series string) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| message | series string | required | The error text shown to the user. Build it with str.tostring() or str.format() to include values. |
Returns
Nothing. The script stops.
Remarks
- The message can be built at run time, for example with
str.tostring()orstr.format(), so it can include the offending value. - A script that stops on a runtime error draws nothing past the failing bar, and every bar it did process before is kept.
- On Sidechair: the script stops on that bar and the message is shown as an error diagnostic with the line and column of the call. A message that is not text is replaced with "The script stopped itself."
Example
//@version=6
indicator("Timeframe guard")
if timeframe.in_seconds() > 7 * 86400
runtime.error("Use a timeframe of one week or shorter. This chart is " + timeframe.period + ".")
plot(close, "Close", color.blue)See also
Runs on Sidechair