SLANG is Symbolik's scripting language to create custom conditions and expressions. SLANG is designed to be intuitive and easy to read, with a clear structure that uses a combination of language components such as price inputs variables, operators, functions, studies, and comments.
Price Inputs
Price Inputs are one of the main building blocks within SLANG to help you construct custom expressions. They represent the price data you would normally see on a chart. The built-in price bar inputs available in SLANG are the following:
Input |
Description |
Close |
The price bar's closing price |
Open |
The price bar's opening price |
High |
The price bar's high price |
Low |
The price bar's low price |
Mid |
The price bar's closing price |
HLC3 |
The arithmetic mean of the price bar’s High, Low, and Close prices |
TrueHigh |
The True High is the high of the current price bar or the previous bar’s close, whichever is higher |
TrueLow |
The True Low is the Low of the current price bar or the previous bar's Close, whichever is lower |
Range |
The difference between the price bar's High and Low prices |
TrueRange |
The difference between the price bar's True High and True Low prices |
Offset
Offsets identify which price bar to apply the condition to. An offset is indicated by using brackets [ ] around the offset value. The offset value can be negative (a price bar in the past), positive (a price bar in the future), or zero (to reference the current price bar). It is not necessary to indicate the current bar, as it is the default.
Offsets can be applied to the built-in price inputs (i.e. Open, High, Close) as well as studies (i.e. Moving Average, RSI, MACD) in SLANG.
Examples:
High[-2] // high price 2 bars ago
Close[-4] // closing price 4 bars ago
Open[1] // opening price 1 bar ahead
Close // closing price on the current bar (equivalent to Close[0])
RSI.RSI[-2] // RSI study 2 bars ago
Symbols
There are 2 types of symbols within SLANG: Floating symbols and Fixed symbols.
Floating Symbol
A floating symbol represents a dynamic data series and can be referenced in your expression using the @
placeholder. When displayed on its own, @
inserts data from the symbol or series currently being evaluated. All the inputs within SLANG use the floating symbol by default so it is not necessary to reference the @
placeholder (i.e. Close
is the same as Close(@)
).
Fixed Symbol
A fixed symbol represents a fixed data series within the expression using the syntax @EXCHANGE:SYMBOL
. When a specific @EXCHANGE:SYMBOL
is tagged, its data is inserted into the expression, regardless of the symbol or series currently being evaluated. For example, if your expression wants to always compare against the opening price of AAPL, you can reference AAPL's opening price in your formula by typing Open(@NASDAQ:AAPL)
.
To find the correct EXCHANGE code for your ticker symbol, you can simply type in @
within the expression box and from the autocomplete menu that appears, select the "floating symbol" option. On the subsequent "Choose a Symbol" menu, type in your ticker symbol and choose from the available options. The correct @EXCHANGE:SYMBOL
tag will then appear within the expression builder.
Example #1:
// you can create a custom index using floating and fixed symbols like below:
aaplSpread: @NASDAQ:AAPL - @;
// the "aaplSpread" above calculates the spread of AAPL and the ticker currently
// loaded on your chart. You can use this custom variable as
// input for your condition:
condition: Close(aaplSpread) > 0;
// you can offset your custom index variable as well:
condition2Ago: Close(aaplSpread)[-2] > 0;
Example #2:
// you can create a condition that only analyzes a specific fixed ticker symbol
vixIndex: @INDEX:VIX;
// using the "vixIndex" variable above, you can create a custom condition to
// determine when the VIX index is above a certain level and apply it to any
// ticker symbol on your chart:
vixAboveLevel: Close(vixIndex) > 20;
Example #3:
// you can apply different symbols on studies and functions as well
spyRSI: RSI.RSI(@CBOEBZX:SPY);
symbolRSI: RSI.RSI(@);
// using the custom variables above, you can create a new custom condition to
// determine when the RSI studies for symbol SPY and the symbol on the chart are
// both above 70:
rsiAbove70: (spyRSI > 70) AND (symbolRSI > 70);
Variables
Variables in SLANG are used to store temporary values and can help simplify complex expressions. Variables are assigned using the following syntax:
VariableName: Value;
A colon symbol (:) is used as the assignment operator and a semi-colon (;) is used to indicate the end of the variable statement. You can assign pre-defined price inputs (Close, Open, High, etc) to custom variables as well as functions, studies, and other complex expressions. Variable names are case-sensitive and should not contain any special characters or spaces.
Examples:
// this creates a custom variable labeled 'barOffset'
barOffset: 2;
// you can use this 'barOffset' variable to offset the High price 2 bars ago.
// This creates another custom variable labeled 'high2Ago'
high2Ago: High[-barOffset];
// you can use 'barOffset' again to offset the Low price 2 bars ago.
// This creates a custom variable labeled 'low2Ago'
low2Ago: Low[-barOffset];
// these custom variables can be used inputs to another variable labeled 'range2Ago'
range2Ago: high2Ago - low2Ago;
Comments
Comments can be added to the condition to provide context or explanations. In Slang, comments are denoted using //
. Any text that follows //
up to a new line will be treated as a comment and ignored when evaluating the condition.
Examples:
// I can write comments here
close2Ago: Close[-2]; // I can write comments here too!
low1Ago: Low[-1]; // More comments!
// I am finished writing comments
Operators
There are 4 types of operators within SLANG:
- Mathematical Operators
- Comparison Operators
- Logic Operators
- Market Operators.
Mathematical Operators
Mathematical operators are used to perform operations on two separate variables or values. This operator will return the numerical value. The a and b variables under the "Syntax" column below can refer to price series data (i.e. Close, Open, Range) or a specific numerical value (i.e. 1.5, 144).
Operator |
Syntax |
Description |
Examples |
+ |
a + b |
Addition |
Close[0] + Open[0] |
- |
a - b |
Subtraction |
High[0] - Low[0] |
* |
a * b |
Multiplication |
Range[0] * 1.5 |
/ |
a / b |
Division |
Close[0] / Close[-2] |
^ |
a ^ b |
Power |
Close[0] ^ 2 |
Comparison Operators
Comparison operators are used in relational statements between different variables or values and will return a True or False output. The a and b variables under the "Syntax" column below can refer to price data (i.e. Close price data) or a specific numerical value.
Operator |
Syntax |
Description |
Examples |
= |
a = b |
Returns True if a is Equal to b |
|
<> |
a <> b |
Returns True if a is Not Equal to b |
|
> |
a > b |
Returns True if a is Greater Than b |
|
>= |
a >= b |
Returns True if a is Greater Than Or Equal to b |
|
< |
a < b |
Returns True if a is Less Than b |
|
<= |
a <= b |
Returns True if a is Less Than Or Equal to b |
|
Logic Operators
Logical operators are used in conditions to combine or modify expressions. These operators can be used with any boolean values or conditions. They are fundamental for creating complex conditional statements in the logic of programming and algorithms. You can use parentheses to control the order of operations when combining these operators. For instance, condition1 AND (condition2 OR condition3) ensures that the OR operation is evaluated before the AND operation.
Operator |
Syntax |
Description |
Examples |
AND |
condition1 AND condition2 |
Returns True if condition1 and condition2 are both True |
|
OR |
condition1 OR condition2 |
Returns True when either condition1 is True or condition2 is True |
|
NOT |
NOT condition |
Returns True if the condition is false, and False if the condition is true |
|
Market Operators
Market operators are used to analyze market conditions based on the movement and trends in price data.
Operator |
Syntax |
Description |
Examples |
Turns Up |
a Turns Up |
Returns True when data series a reverses its direction from downward to upward |
|
Turns Down |
a Turns Down |
Returns True when data series a reverses its direction from upward to downward |
|
Going Up |
a Going Up |
Returns True when a continues it's upward trend direction |
|
Going Down |
a Going Down |
Returns True when a continues it's downward trend direction |
|
Cross Above |
a Cross Above b |
Returns True when a crosses above b |
|
Cross Below |
a Cross Below b |
Returns True when a crosses below b |
|
When |
a When condition |
Returns data series a when condition registers as True |
|
Functions
SLANG provides built-in functions to assist you in creating expressions. The built-in functions available include the following:
AbsoluteValue
-
Description: The
AbsoluteValue
function calculates the non-negative absolute value of a given input(s). It can be used with any real number, along with price series data and variables.
-
Syntax:
AbsoluteValue(Datum)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
-
-
Examples:
// real numeric values can be used as inputs
AbsoluteValue(-15)
// price series data and formulas can be used as inputs as well
AbsoluteValue(Close - Open)
Average
-
Description: The
Average
function calculates the arithmetic mean of a given set of values (Datum) over a specified period of time (Period). The values can be any numerical inputs, such as opening prices, closing prices, or numerical output from other functions or studies. The function returns a single numerical value representing the average of the input values over the specified range.
-
Syntax:
Average(Datum, Period)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Period: A positive integer that establishes the range over which the datum is evaluated.
-
-
Examples:
// this will calculate the average closing price for the last 50 price bars
Average(Close, 50)
// you can calculate the average on custom formulas as well
Average((Close[0] - Close[-2]) * 2, 20)
BarsSince
-
Description: The
BarsSince
function returns the number of bars that have passed since the condition or expression was last true. This function is commonly used in time series analysis to determine how long ago a specific condition was met and will always be relative to the currently evaluating bar.
-
Syntax:
BarsSince(Boolean)
-
Parameters:
-
- Boolean: This parameter represents a condition or an expression that results in a Boolean value (i.e. returns a value of True or False)
-
-
Examples:
// This will calculate how many price bars has it been since the closing price
// was greater than opening price
BarsSince(Close > Open)
// the formula below will return as True if there has been 2 or more price bars
// since the closing price was greater than the opening price
BarsSince(Close > Open) >= 2
Consecutive
-
Description: The
Consecutive
function checks whether a series of conditions or expressions holds true consecutively over a specific number of price bars. The function will return as either True or False
-
Syntax:
Consecutive(Boolean, Period)
-
Parameters:
-
- Boolean: This parameter represents a condition or an expression that results in a Boolean value (i.e. returns a value of True or False)
- Period: A positive integer that establishes the range over which the datum is evaluated.
-
-
Examples:
// If the close has been greater than the open for 3 consecutive price bars,
// then following function will return as True
Consecutive(Close > Open, 3)
If
-
Description: The
If
function evaluates a given condition and returns one value if the condition is True and another value if the condition is False. This function can be used to create conditional expressions, which are a fundamental part of many programming and scripting languages.
-
Syntax:
If(Boolean, TrueOutput, FalseOutput)
-
Parameters:
-
- Boolean: This parameter represents a condition or an expression that results in a Boolean value (i.e. returns a value of True or False)
- TrueOutput: This is the Datum returned if the condition is True.
- FalseOutput: This is the Datum returned if the condition is False.
-
-
Examples:
// In the following If statement, if the current close is greater than the
// current open, then the current close is used. If the close is less than
// the open, then the close 1 bar ago is used
If(Close > Open, Close, Close[-1])
Log
-
Description: The
Log
function computes the natural logarithm (base e) of a given input.
-
Syntax:
Log(Datum)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
-
-
Examples:
// This calculates the natural logarithm of the closing price
Log(Close)
Log10
-
Description: The
Log10
function computes the base-10 logarithm of a given input
-
Syntax:
Log10(Datum)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
-
-
Examples:
// This calculates the base-10 logarithm of the closing price
Log10(Close)
Maximum
-
Description: The
Maximum
function identifies the higher value between two inputs.
-
Syntax:
Maximum(Datum1, Datum2)
-
Parameters:
-
- Datum1: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Datum2: A real number or Price, Function, Study, Condition, Variable, or Formula output.
-
-
Examples:
// this will take the higher value between the current High and the Close 1 bar ago
Maximum(High, Close[-1])
MaximumOverPeriod
-
Description: The
MaximumOverPeriod
identifies the highest value over a specified period of time.
-
Syntax:
MaximumOverPeriod(Datum, Period)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Period: A positive integer that establishes the range over which the datum is evaluated.
-
-
Examples:
// this will calculate the maximum closing price over the last 50 price bars
MaximumOverPeriod(Close, 50)
MaximumSince
-
Description: The
MaximumSince
function is used to find the highest value observed in a series since a specified condition was met.
-
Syntax:
MaximumSince(Datum, Boolean)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Boolean: This parameter represents a condition or an expression that results in a Boolean value (i.e. returns a value of True or False)
-
-
Examples:
// this will calculate the maximum high price since the RSI study crossed below 70
MaximumSince(High, RSI.RSI Cross Below 70)
Minimum
-
Description: The
Minimum
function identifies the lower value between two inputs.
-
Syntax:
Minimum(Datum1, Datum2)
-
Parameters:
-
- Datum1: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Datum2: A real number or Price, Function, Study, Condition, Variable, or Formula output.
-
-
Examples:
// this will take the lower value between the current Low and the Close 1 bar ago
Minimum(Low, Close[-1])
MinimumOverPeriod
-
Description: The
MinimumOverPeriod
identifies the lowest value over a specified period of time.
-
Syntax:
MinimumOverPeriod(Datum, Period)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Period: A positive integer that establishes the range over which the datum is evaluated.
-
-
Examples:
// this will calculate the minimum closing price over the last 50 price bars
MinimumOverPeriod(Close, 50)
MinimumSince
-
Description: The
MinimumSince
function is used to find the lowest value observed in a series since a specified condition was met.
-
Syntax:
MinimumSince(Datum, Boolean)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Boolean: This parameter represents a condition or an expression that results in a Boolean value (i.e. returns a value of True or False)
-
-
Examples:
// this will calculate the minimum low price since the RSI study crossed above 70
MinimumSince(Low, RSI.RSI Cross Above 70)
SquareRoot
-
Description: The
SquareRoot
function is used to calculate the square root of a datum within a series.
-
Syntax:
SquareRoot(Datum)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
-
-
Examples:
// this will calculate the Square Root of the closing price
SquareRoot(Close)
StandardDeviation
-
Description: The
StandardDeviation
function is used to calculate the standard deviation, a measure of the amount of variation or dispersion, for a series of numeric values over a specified period.
-
Syntax:
StandardDeviation(Datum, Period)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Period: A positive integer that establishes the range over which the datum is evaluated.
-
-
Examples:
// this will calculate the standard deviation of the closing price for the last
// 50 price bars
StandardDeviation(Close, 50)
Sum
-
Description: The
Sum
function computes the total sum of a series of numeric values over a specified period.
-
Syntax:
Sum(Datum, Period)
-
Parameters:
-
- Datum: A real number or Price, Function, Study, Condition, Variable, or Formula output.
- Period: A positive integer that establishes the range over which the datum is evaluated.
-
-
Examples:
// this will calculate the sum of the closing price for the last 10 price bars
Sum(Close, 10)
Time
-
Description: The
Time
function includes a group of functions designed to extract specific temporal elements from a data series.
-
Syntax:
Time.Month()
Time.Year()
Time.Day()
Time.Hour()
Time.Minute()
Time.Weekyear()
Time.WeekOfWeekyear()
Time.DayOfYear()
Time.DayOfWeek()
Time.MinuteOfDay()
-
Examples:
// Time.Month() returns the month of the data series (1 to 12)
monthOfMarch: Time.Month() = 3;
// Time.Year() returns the year of the data series
year2022: Time.Year() = 2022;
// Time.Day() returns the day of the month (1 to 31)
day5ofMonth: Time.Day() = 5;
// Time.DayOfWeek() returns the day of the week (0 to 6 where 0 represents Sunday)
friday: Time.DayOfWeek() = 5;
// Time.DayOfYear() returns the day of the year (1 to 366).
day100ofYear: Time.DayOfYear() = 100;
// Time.Weekyear() Weeks start on a Monday, Week # 1 has the first Thursday
// of the calendar year, and A year consists of either 52 or 53 whole weeks.
week1ofYear: Time.Weekyear() = 1;
// Time.WeekOfWeekyear() The week of the year (1 to 53).
week1ofWkYear: Time.WeekOfWeekyear() = 1;
// Time.Hour() returns the hour of the day (0 to 23)
noonHour: Time.Hour() = 12;
// Time.Minute() returns the minute of the hour (0 to 59)
fifthMinuteOfHour: Time.Minute() = 5;
// Time.MinuteOfDay() returns the minute of the day (0 to 1439).
minute2OfDay: Time.MinuteOfDay() = 2;
Within
-
Description: The
Within
function is designed to evaluate a specific condition over a range of periods or bars in a data series and check if it meets the set condition a certain number of times.
-
Syntax:
Within(Boolean, Period, Count)
-
Parameters:
-
- Boolean: This parameter represents a condition or an expression that results in a Boolean value (i.e. returns a value of True or False)
- Period: A positive integer that establishes the range over which the datum is evaluated.
- Count: This is the minimum number of times the condition needs to be true within the specified range. The Within function will return 'True' if the number of times is greater than or equal to this number
-
-
Examples:
// the Within function checks if the current close is higher than the previous bar's
// close. It returns True if this condition is met at least 6 times within
// the last 10 bars.
Within(Close > Close[-1], 10, 6)
Studies
SLANG provides the ability to incorporate studies in your custom expressions. Studies in SLANG use the following syntax:
StudyName.Preset.OutputName
A preset value is not required for referencing studies within SLANG. If a preset is not specified, the default preset settings for that particular study will be used. The StudyName and OutputName are required.
To get further information on all the available technical studies in Symbolik, click HERE.
Examples:
// this references the UpperBand output for the Bollinger Bands study
upperBand: BollingerBand.Preset1.UpperBand;
// the 'Preset' is not required so the following syntax is also acceptable:
upperBandNoPreset: BollingerBand.UpperBand;
// you can reference studies on fixed ticker symbols
upperBand_AAPL: BollingerBand.UpperBand(@NASDAQ:AAPL);
// you can also offset studies
upperBand_AAPL_2Ago: BollingerBand.UpperBand(@NASDAQ:AAPL)[-2];