runtime namespace
runtime
Section titled “runtime”Overview
Section titled “Overview”The runtime namespace currently provides runtime.error(), a helper that lets your script stop execution intentionally with a descriptive message. Throwing custom runtime errors is useful when user inputs are invalid, when a required data request fails, or when continuing would lead to misleading results.
Runtime errors halt the script immediately. Use them sparingly and make the message actionable (e.g., “Increase max_bars_back to at least 500”).
Syntax
Section titled “Syntax”runtime.error(message) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
message | series string | Explanation shown in the Pine Editor and on the chart when the error is triggered. |
Remarks
Section titled “Remarks”- Messages can contain dynamic values (
runtime.error("Invalid length: " + str.tostring(len))), but avoid expensive computations inside the call. - When feasible, prefer guarding logic with conditional branches instead of raising errors so users can continue using the script.
- Combine with user inputs to validate bounds or dependencies between settings.
Example
Section titled “Example”//@version=5indicator("runtime.error() guard", overlay=false)
lookback = input.int(10, "Lookback", minval=1)threshold = input.float(0.0, "Threshold (0-1)")
if threshold < 0 or threshold > 1 runtime.error("Threshold must stay between 0 and 1.")
avg = ta.sma(close, lookback)plot(avg, "Moving average", color=color.teal)