Reference6 min read
Helper functions for common trading calculations and signal detection.
highest()
Find the highest value over a specified period.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
source | TimeSeries | Source data series |
period | number | Lookback period |
Example
lowest()
Find the lowest value over a specified period.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
source | TimeSeries | Source data series |
period | number | Lookback period |
Example
crossover()
Detect when one series crosses above another.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
series1 | number | First series (the one crossing over) |
series2 | number | Second series (being crossed) |
Example
crossunder()
Detect when one series crosses below another.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
series1 | number | First series (the one crossing under) |
series2 | number | Second series (being crossed) |
Example
change()
Calculate the change from a previous value.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
source | number | Current value |
period | number | Lookback period (default: 1) |
Example
valuewhen()
Get a value when a condition was true.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
condition | boolean | Condition to check |
source | number | Value to retrieve |
occurrence | number | Which occurrence (0=most recent) |
Example
barssince()
Count bars since a condition was true.Signature
Parameters
| Parameter | Type | Description |
|---|---|---|
condition | boolean | Condition to check |
Example
print()
Output debug information to the console.Signature
Example
Practical Examples
Donchian Channel
MA Crossover Strategy
Price Range Analysis
Tips
Crossover Detection
Crossover functions check if the crossing happened on the current bar. Use them in conditional logic:Period Selection
Forhighest() and lowest(), common periods are:
- 20 bars for short-term range
- 52 bars for annual high/low (weekly charts)
Debugging
Useprint() liberally during development to verify calculations.