Set of functions containing the built-in scripting operators, such as moving average calculations.
Members
-
sma
-
sma: compute simple moving average calculation
Same as ma
Methods
-
cmo(state, field, lookback)
-
cmo: compute a Chande Momentum calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
cmo for the close with a period of 50
result = stddev('Close', 50)
use built-in to create a Chande Momentum study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the cmo builtin that calculates a Chande Momentum cmo = cmo(field, period) plot(cmo, color: "orange")
-
dataset(state [, field] [, lookback])
-
dataset: pull quote values out of the (scrubbed) symbol values
Parameters:
Name Type Argument Default Description state
object Plugin state
field
string <optional>
"Close" Field in dataset
lookback
number <optional>
0 Number of records from current to look at (looking backwards)
Returns:
Value of quote for the field requested
- Type
- number | null
Examples
close from the current quote
close = dataset('Close')
close from the previous quote
close = dataset('Close', -1)
implement a simple moving average
study("Simple MA") field = input("Field", "field") period = input("Period", 20) sum = (length) -> total = 0 while length value = dataset(field, -(--length)) return null if not value? total += value total total = sum period if total? average = total / period plot average
-
ema(state, field, lookback)
-
ema: compute exponential moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
ema for the close with a period of 50
result = ema('Close', 50)
use built-in to create an exponential simple moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the ema builtin that calculates an exponential moving average ema = ema(field, period) plot(ema, color: "orange")
-
fill(state, topBand, bottomBand [, params])
-
Create parameters for {CIQ.prepareChannelFill}. Store in sd.scriptStates.
Parameters:
Name Type Argument Description state
object Plugin state
topBand
string Field representing top band
bottomBand
string Field representing bottom band
params
object <optional>
Plotting parameters
Properties
Name Type Argument Description color
string | object <optional>
Color of plot
Example
Fill the area between two indicator lines
top = dataset("High") bottom = dataset("Low") topBand = plot(top) bottomBand = plot(bottom) fill(topBand, bottomBand, color: "green")
-
histogram(state, field [, params])
-
Set the value in the dataset to create a histogram. There can only be a single histogram per study.
Parameters:
Name Type Argument Description state
object Plugin state
field
string Field to plot
params
object <optional>
Plotting parameters
Examples
Simple histogram with default colors
histogram(field)
Histogram with custom positive & negative colors
histogram(field, colorPositive: '#01ff01', colorNegative: '#ff0101')
Histogram with custom increasing & decreasing colors
histogram(field, colorIncreasing: '#0101ff', colorDecreasing: '#767600', opacity: 0.4)
-
input(state, field)
-
Parameters:
Name Type Description state
object Plugin state
field
string Input field name
Returns:
Value of input field
- Type
- number | string
-
ma(state, field, lookback)
-
ma: compute a simple moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
ma for the close with a period of 50
result = ma('Close', 50)
use built-in to create a complete simple moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the ma builtin that calculates a simple moving average simple = ma(field, period) plot(simple, color: "orange")
-
plot(state, field [, params])
-
plot: plots a line on the chart
Parameters:
Name Type Argument Description state
object Plugin state
field
string Field to plot
params
object <optional>
Returns:
Name of plot
- Type
- string
Example
plot an orange line for data belonging to field
plot(field, color: "orange")
-
series(state, field)
-
Parameters:
Name Type Description state
object Plugin state
field
string Series field name
-
smma(state, field, lookback)
-
smma: compute welles-wilder moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
smma for the close with a period of 50
result = smma('Close', 50)
use built-in to create a welles-wilder moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the smma builtin that calculates a welles-wilder moving average smma = smma(field, period) plot(smma, color: "orange")
-
stddev(state, field, lookback, options)
-
stddev: Standard Deviation calculation.
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
options
object Returns:
- Type
- number | null
Examples
stddev for the close with a period of 50
result = stddev('Close', 50)
use built-in to create a Standard Deviation study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the stddev builtin that calculates a Standard Deviation stddev = stddev(field, period) plot(stddev, color: "orange")
-
tma(state, field, lookback)
-
tma: compute triangular moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number
Examples
tma for the close with a period of 50
result = tma('Close', 50)
use built-in to create a triangular moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the tma builtin that calculates a triangular moving average tma = tma(field, period) plot(tma, color: "orange")
-
tsma(state, field, lookback)
-
tsma: compute time-series moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
tsma for the close with a period of 50
result = stma('Close', 50)
use built-in to create a time-series moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the tsma builtin that calculates a time-series moving average tsma = tsma(field, period) plot(tsma, color: "orange")
-
vdma(state, field, lookback)
-
vdma: compute vidya (based on variable) moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
vdma for the close with a period of 50
result = vdma('Close', 50)
use built-in to create a vidya moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the vdma builtin that calculates a vidya moving average vdma = vdma(field, period) plot(vdma, color: "orange")
-
vma(state, field, lookback)
-
vma: compute variable moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
vma for the close with a period of 50
result = vma('Close', 50)
use built-in to create a variable moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the vma builtin that calculates a variable moving average vma = vma(field, period) plot(vma, color: "orange")
-
wma(state, field, lookback)
-
wma: compute weighted moving average calculation
Parameters:
Name Type Description state
object Plugin state
field
string Field to compute upon
lookback
number Number of records from current to look at (looking backwards), aka Period
Returns:
- Type
- number | null
Examples
wma for the close with a period of 50
result = wma('Close', 50)
use built-in to create a weighted moving average study
study("Hello World") field = input("Field", "Close") # Define the Period input for the study period = input("Period", 50) # Use the wma builtin that calculates a triangular moving average wma = wma(field, period) plot(wma, color: "orange")