Formula Screener
is the most powerful tool we provide in our service.
Whereas regular stock screener applies "and" condition to all selected criteria (i.e. all criteria must be met for a stock to be selected),
the Formula Screener allows you to combine "and", "or" and "not" conditions
to build very specific criteria.
Moreover, the Formula Screener tool gives you the possibility to combine criteria on different time periods.
Other words, it is possible to find stocks that meet some conditions on a daily chart and other conditions on weekly or monthly charts.
It worth to mention that the historical screening feature gets more flexible in the Formula Screener.
You can specify offset value for any criteria in a formula expression in days or in weeks or months if
the corresponding time periods were set for the criteria.
Range screening leverages the above approach and provides you with the ability to set a condition to be met within some period
of time. Let say you may allow moving average crossover to occur within last 3 days or require an oscillator
to be in oversold zone all time last 10 days.
Please note, that when combining many conditions in a formula, it is important to use parentheses so that the screener
knows what order to evaluate each condition.
The following examples demonstrate how to code maximally flexible criteria in formula expressions:

Formula Example

Explanation

Simple expressions

exch(nasdaq)
and cap > 1
and price >= 5
and avol > 1
and price casma(50)

Exchange: NASDAQ and Capitalization > 1 million and Price > 5 and Average Volume > 1 million and Price Crossed Above MA(50)

avol in this formula stands for a 21-day average daily volume. Note that avol and cap are in millions.

exch(nasdaq, nyse)
and price trend_up 7
and ( rsi(14) div_bull
or macd(12,26,9) div_bull )

Exchange: NASDAQ or NYSE and Price Trending Up Last 7 Days and ( RSI(14) Bullish Divergence or MACD(12,26,9) Bullish Divergence )

avol > 1
and gapup > 20
and rsi(14) < 80

Average Volume > 1 million and Gap Up is Greater than 20% and RSI(14) is Below 60

NYSE and NASDAQ exchanges will be used by default in this formula.

type(stock) and advol > 100

Find only regular stocks (excluding ETFs) having an average dollar volume greater than 100 million.

advol in this formula is in millions and stands for a 21-day average daily dollar volume.
For finding ETFs with the same condition, the formula may look like this:
type(fund) and advol > 100

Negate operator

exch(nasdaq, nyse)
and ! sector(financial)
and ! industry(425,426,427)
and price ca bbub(20,2)

Exchange: NASDAQ or NYSE
and not Financial sector
and not an industry with code 425, 426 or 427
and Price Crossed Above Upper Band of BBands(20,2)

price trend_up 200
and !
( rsi(14) div_bear )

Price Trending Up Last 200 Days and not "RSI(14) Bearish Divergence"

Using different time periods

( rsi(20) ia 50 )@monthly
and ( price ia ema(20) )@weekly
and ( price ca sma(7) )@daily

RSI(20) Is Above 50 on monthly periods and
Price Is Above EMA(20) on weekly periods and
Price Crossed Above SMA(7) on daily periods

( cdl_ham @daily or cdl_buki @daily )
and ( cdl_lowl@weekly
or cdl_bu3ws@weekly
or cdl_wb@monthly )

Hammer or Bullish Kicker on daily periods and
Long White Line or Three White Soldiers on weekly periods or White Body on monthly periods

exch(iex)
and ( price ca sma(50) )@hourly

Exchange: IEX and Price Crossed Above SMA(50) on hourly periods

Please note that hourly periods are supported only for IEX and Forex exchanges.

Historical screening

(ema(7) ca ema(50))@2 and cdl_ham@1

EMA(7) Crossed Above EMA(50) 2 days ago
and "Hammer" 1 day ago
(The @2 and @1 designators here specify shift relative to the current bar the given amount of periods ago)

(price ca sma(7))@2@weekly
and (chopen > 5)@1@daily

Price Crossed Above SMA(7) on weekly periods 2 weeks ago
and Change From Open > 5% yesterday
(The @2 and @1 designators here specify shift relative to the current bar the given amount of periods ago)

sma(50) > sma(50)@10

Current value for SMA(50) is greater than value for SMA(50) taken 10 days ago

price ca sma(100) and hist(12/31/2019)

Find stocks for which the price has crossed above SMA(100) on December 31, 2019.
The Stock Screener will only select tickers that match the formula expression as of the specified date.
The date should be indicated in a short date format: month/day/year.

Range screening

(rsi(14) ca 80)@[0..4]

RSI(14) indicator crossed above 80 within the last 5 days/bars. This formula is equivalent to
(rsi(14) ca 80)@0
or (rsi(14) ca 80)@1
or (rsi(14) ca 80)@2
or (rsi(14) ca 80)@3
or (rsi(14) ca 80)@4

Note that in this example, we used square brackets.

(rsi(14) ia 80)@{0..4}

RSI(14) indicator is above 80 during the last 5 days/bars. This formula is equivalent to
(rsi(14) ia 80)@0
and (rsi(14) ia 80)@1
and (rsi(14) ia 80)@2
and (rsi(14) ia 80)@3
and (rsi(14) ia 80)@4

Note that in this example, we used curly brackets.

( rsi(14)@fixed > rsi(14 )@1)@{0..9}

RSI(14) indicator has reached its maximum value in the last ten days.
This formula is equivalent to rsi(14) > rsi(14)@1 and rsi(14) > rsi(14)@2 and .. and rsi(14) > rsi(14)@10. Note that in this example, we used curly brackets.

Range shifts are not applied to a @fixed expression, allowing it to have a fixed value. As if we can build loops, leaving some expressions inside the loop unchanged.

( close[0]@fixed > close[1] )@[0..9]

Today's closing price is higher than the closing price of at least one of the last ten days.
This formula is equivalent to close[0] > close[1] or close[0] > close[2] or .. or close[0] > close[10]. Note that in this example, we used square brackets.

Using data arrays

high[1] > high[2]
and low[1] > low[2]
and v[1] > 2 * v[2]
and close[0] > high[1]
and open[0] > low[1]

The previous bar shows ascending high and low with doubling volume
and the current price is greater than the previous high
and the open price is greater than the previous low

Note that the following abbreviations can be used to indicate the current values of open, high, low, and close prices:
open = o, high = h, low = l, close = c = last = price

At least four of the five conditions in the expression must be met.

Depending on Index / Ticker conditions

(ema(7) > ema(200))@sp500 and
rsi(14) ca 80

Find stocks for which RSI(14) crossed above 80. Give any results only if
EMA(7) is above EMA(200) on the S&P 500 chart.
Any ticker name or the following index tokens can be used:
dow, sp500, nasdaq, nasd100, ru1000, ru2000, ru3000, rumid, rumicro, tsx, ftse100, ftse250, ftseall,
dax, hsi, sti, asx50, asx200, klci, vix, axvi.

(advdec trend_up 10)@nasdaq
and (mo > 0)@nasdaq
and (msi > 0)@nasdaq and
rsi(14) ca 80

Find stocks for which RSI(14) crossed above 80. Give any results only if
Nasdaq Composite Advance/Decline is trending up last 10 days and both McClillan Oscillator and Summation Index are above zero.

(price > ema(200))@aapl and
rsi(14) ca 80

Find stocks for which RSI(14) crossed above 80. Give any results only if
price is above EMA(200) on the AAPL chart.

Conditional expressions

rsi(14) ca if(price > ema(21), 60, 40)

This formula expression will work like rsi(14) ca 60 in case if price > ema(21) and as rsi(14) ca 40 otherwise.
It is worth noting that this expression is a shorter form for (price > ema(21) and rsi(14) ca 60) or (price <= ema(21) and rsi(14) ca 40).

Fundamental criteria

exch(nasdaq,nyse)
and eps > 5
and pe < 10
and roi > 50

Exchange: NASDAQ or NYSE and EPS > 5 and P/E < 10 and ROI > 5

sector( financial,
technology, services )
and tip_ptpm
> 100 and tip_ebitda > 100

"Sector is one of the following ( Financial, Technology, Services )
and "Pre-tax Profit Margin to Indystry Avg, %" > 100%
and "Earnings to Indystry Avg, %" > 100%

The current EPS is two times higher the EPS for 12 months ago, and the EPS for 12 months ago is two times higher the EPS for 24 months ago

Technical criteria

( fibo_ta23
or fibo_ta38
or fibo_ta50 )
and ln_art

( "Price Touched 0.23 Fibonacci Support Level"
or "Price Touched 0.38 Fibonacci Support Level"
or "Price Touched 0.50 Fibonacci Support Level" )
and "Price Is Above Rising Trend Line" )

cap > 100 and price < 50
and ( cdl_lowl or price risunvol )

Capitalization > 100 mln
and Price < 50
and ( "Long White Line" or "Rising on Unusual Volume" )

( price ca sma(200) or price ca sma(50) )
and rsi(14) div_bull

( "Price Crossed Above MA(200)"
or "Price Crossed Above MA(50)" )
and "RSI(14) Bullish Divergence"

Heikin Ashi chart criteria

(price ca sma(50))@heikin

For any condition, you can indicate that it must apply to the Heikin Ashi chart.

Price crossed above SMA(50) on the Heikin Ashi chart.

(price < sma(50))@heikin and price ca sma(50)

Price is lower than SMA(50) on the Heikin Ashi chart, but it crossed above SMA(50) on a classical bar chart.

(price higher_closes 5)@heikin@weeks

A five-candlestick series of rising closing prices on the weekly periods of the Heikin Ashi chart.

Output instructions

rsi(7) trend_up 5
and sortby(rsi(7), asc)

RSI(7) is trending up over the last 5 days. Stock Screener results will be sorted in ascending order by the RSI(7) indicator value.
We could also just write sortby(rsi(7)) here since the ascending order will be used by default.

The sortby function can also be used in the Strategy Backtest tool to set more flexible prioritization when adding stocks to the trading portfolio.
In this case, the criteria for opening a position should be set using a formula expression.

rsi(7) trend_dn 5
and sortby(rsi(7), desc)

RSI(7) is trending down over the last 5 days.
Stock Screener results will be sorted in descending order by the RSI(7) indicator value.

enterprise_ebitda < 15
and sortby(dvd_yield, desc, 10)

Enterprise Value to EBITDA ratio is less than 15. Stock Screener results will be sorted by dividend yield
in descending order and only the top 10 stocks will be selected.

rsi(14) ca 30
and show(rsi(14))

Find stocks for which the RSI(14) indicator crossed above 30 and add the "RSI(14)" column to the Stock Screener results page.
Columns will be added to the right of the standard columns of the stock screen and will display the corresponding values for each ticker.
The indicators listed in the show function will also be plotted on charts that are opened from the stock screen
and on mini charts when switching to the "Charts" view.

rsi(7) ca rsi(14)
and rsi(7) < 30
and show(rsi(7), rsi(14), ebitda, dvd_yield, pe)

Find stocks for which the RSI(7) line crossed above RSI(14) and RSI(7) is less than 30 and
add RSI(7), RSI(14), ebitda, dividend yield and P/E ratio columns to the Stock Screener results page.

rsi(14) ca 30
and show(rsi(14) - smarsi(14,9) as diff)

Find the stocks for which the RSI(14) crossed above 30 and add a column named "diff", showing the difference between the RSI(14) and the 9-period simple moving average of RSI(14) on the Stock Screener results page.

ema(100) trend_up 100
and draw(rsi(7), rsi(14))

EMA(100) is trending up over the last 100 days.
The RSI(7) and RSI(14) indicators listed in the draw function will be plotted on charts that are opened from the Stock Screener
results page and on mini charts when switching to the "Charts" view.

Access to a trading position in the backtesting tool

price < posprice - 1

Formula expression can be used as a criteria for closing a position in the Strategy Backtest tool.
This can be done by ticking the "Extract criteria from screen" option and selecting the appropriate formula screen.
In this formula, you can get the value of the price at which the position was opened using the "posprice" literal.

In this example, we want to close a position as soon as the current price has fallen below the purchase price minus one dollar.

price cb sma(7) and price > 1.2 * posprice

In this example, we close the position when the price crosses down SMA(7), but only if the profit is already more than 20%.

You can also get access to the position's stop loss and take profit by using the posstop and postake variables correspondingly.

price < low[posbar]

You can get the index of the day/bar on which the position was opened using the "posbar" literal.
In this example, we want to close the position as soon as the current price has fallen below the low price formed on the day the position is opened.

rsi(14) < evalat(rsi(14), posbar)

You can get the value of the indicator or expression at the moment the position was opened using the "posbar" literal and the "evalat" function.
In this example, we want to close the position as soon as the current value of the RSI(14) falls below the value of the RSI(14) recorded on the day the position was opened.

posage = 5

You can get the number of days/bars elapsed since the position was opened.
In this example, we want to close a position 5 days after it was opened.

stopat(psar(0.02,0.2))

Instructs the trading simulator to move the stop loss level to the specified value.
As a parameter, you can specify an indicator,
function, or other formula expression that returns a numerical value.
If the expression for closing a position has already been set, then the function must be added using the "or" operator.
For example: rsi(14) < 60 or stopat(psar(0.02,0.2)).
Please note that the "stopat" function is applied with a one day/bar delay. That is, stop loss is
calculated on the current day/bar but will be applied on the next day/bar.

takeat(bbub(20,2))

Instructs the trading simulator to move the take profit level to the specified value.
As a parameter, you can specify an indicator,
function, or other formula expression that returns a numerical value.
If the expression for closing a position has already been set, then the function must be added using the "or" operator.
For example: rsi(14) > 75 or takeat(bbub(20,2)).
Please note that the "takeat" function is applied with a one day/bar delay. That is, take profit is
calculated on the current day/bar but will be applied on the next day/bar.

if(price > 1.05 * posprice, stopat(low[0]))

The IF function can be useful in the formula for closing a position in combination with the STOPAT or TAKEAT instructions.
In this formula, the stop loss will be set at the day's low level, but only if the position's profit is more than 5%.
If the expression for closing a position has already been set, then the function must be added using the "or" operator.
For example: rsi(14) < 60 or if(price > 1.05 * posprice, stopat(low[0]))

Comments

price ca sma(200) /* comments here */

You may add your comments inside a formula expresssion

You may write a formula directly in the Formula text area or use
Formula Expression Helper pane to build certain conditions and insert them into the formula one by one:
Select criteria Category and Group first, then chose specific criterion or technical event you would like to add to the formula expression.
The selected condition will appear in the Expression text field. It allows edits so you may adjust parameters before adding the condition to the formula.
Hit Insert into formula button to add the condition to the formula expression. Add other conditions the same way if necessary and perform final edits
of the expression in the Formula text area. To view matched stocks click on Run Screen link:

The following table contains the full list of indicators that can be used in formula expression.
They can also be accessed with the usage of Formula Expression Helper.

Indicator Example

Explanation

ac(5,34,5)

Accelerator Oscillator

ad

Accumulation / Distribution

advdec

Advance/Decline Line

advdecvol

Advance/Decline Volume Line

adx(14)

Average Directional Movement Index

ao(5,34)

Awesome Oscillator

aroon(25)

Aroon Indicator

aroonosc(25)

Aroon Oscillator

atr(14)

Average True Range

bs(5)

Balance Step

bbands(20,2)

Bollinger Bands

bb(20,2)

Bollinger BandWidth, %

pb(20,2)

Bollinger %B

bbub(20,2)

Upper Band of Bollinger Bands

bblb(20,2)

Lower Band of Bollinger Bands

beta(5)

Beta

bop

Balance Of Power

chandexit(22,3)

Chandelier Exit

chmo(9)

Chande Momentum Oscillator

cho(3,10)

Chaikin Oscillator

chop(14)

Choppiness Index

cci(18)

Commodity Channel Index

cmf(20)

Chaikin Money Flow

crsi(3,2,100)

Connors RSI

dema(50)

Double Exponential Moving Average

dim(14)

Negative Directional Indicator (-DI)

dip(14)

Positive Directional Indicator (+DI)

ema(50)

Exponential Moving Average

ema(50,7)

Forward shifted Exponential Moving Average. The extra "7" at the end is the shifting parameter.

emah(50)

Exponential Moving Average applied to high prices

emal(50)

Exponential Moving Average applied to low prices

emae(50,20)

Exponential Moving Average Envelope

emaeub(50,20)

Upper Bound of Exponential Moving Average Envelope

emaelb(50,20)

Lower Bound of Exponential Moving Average Envelope

emaobv(20)

Exponential Moving Average of OBV

emarsi(14,9)

Exponential Moving Average of RSI

emv(14)

Ease of Movement

force(14)

Elder Force Index

hma(50)

Hull Moving Average

ichimoku(9,26,52)

Ichimoku

tenkan(9,26,52)

Ichimoku, Tenkun Line

kijun(9,26,52)

Ichimoku, Kijun Line

spana(9,26,52)

Ichimoku, Span A Line

spanb(9,26,52)

Ichimoku, Span B Line

chikou(9,26,52)

Ichimoku, Chikou Line

kama(30)

Kaufman Adaptive Moving Average

keltub(20,2,10)

Keltner Upper Band

keltlb(20,2,10)

Keltner Lower Band

kdj(9,3,3)

KDJ Indicator K-Line

kdjd(9,3,3)

KDJ Indicator D-Line

kdjj(9,3,3)

KDJ Indicator J-Line

macd(12,26,9)

MACD

macds(12,26,9)

MACD Signal Line

macdh(12,26,9)

MACD Histogram

mama(0.5,0.05)

MESA Adaptive Moving Average

mfi(14)

Money Flow Index

mhigh

Monthly Previous High

mlow

Monthly Previous Low

mclose

Monthly Previous Close

mi(25)

Mass Index

minusvi(14)

Vortex Indicator -VI Line

mo

McClellan Oscillator

mvo

McClellan Volume Oscillator

mom(12)

Momentum

msi

McClellan Summation Index

mvsi

McClellan Volume Summation Index

natr(14)

Normalized Average True Range

nhnl

New Highs - New Lows

obv

On Balance Volume

pp

Pivot Point

pb(20,2)

Bollinger %B

ps1

Pivot Point (S1)

ps2

Pivot Point (S2)

pr1

Pivot Point (R1)

pr2

Pivot Point (R2)

plusvi(14)

Vortex Indicator +VI Line

ppo(12,26,9)

Percentage Price Oscillator

ppoh(12,26,9)

PPO Histogram

psar(0.02,0.2)

Parabolic SAR

qstick(8,5)

QStick

qsticks(8,5)

QStick Signal Line

range(5)

Range

roc(10)

Price Rate of Change

rci(10)

Rank Correlation Index

rmi(14,10)

Relative Momentum Indicator

rs5

1-Week Relative Strength

rs10

2-Week Relative Strength

rs21

1-Month Relative Strength

rs68

3-Month Relative Strength

rs126

6-Month Relative Strength

rs252

1-Year Relative Strength

rsi(14)

Relative Strength Index

sma(50)

Simple Moving Average

sma(50,7)

Forward shifted Simple Moving Average. The extra "7" at the end is the shifting parameter.

Upper Line of Linear Regression Channel (period, number of standard deviations)

mlr(100,2)

Middle Line of Linear Regression Channel (period, number of standard deviations)

llr(100,2)

Lower Line of Linear Regression Channel (period, number of standard deviations)

slr(100,2)

Slope of Linear Regression Channel (period, number of standard deviations)

vma(20)

Volume Moving Average

vo(7,14)

Volume Oscillator

vr(21)

Volume Ratio

vstop(20,2)

Volatility Stop

vwma(50)

Volume Weighted Moving Average

wad

William's Accumulation / Distribution

wavetrend(10,21)

WaveTrend Oscillator

wts(10,21)

WaveTrend Signal Line

wild(21)

Wilder Moving Average

wma(50)

Weighted Moving Average

wma(50,7)

Forward shifted Weighted Moving Average. The extra "7" at the end is the shifting parameter.

wpr(14)

Williams` Percent Range

whigh

Weekly Previous High

wlow

Weekly Previous Low

wclose

Weekly Previous Close

yhigh

Yealy Previous High

ylow

Yealy Previous Low

yclose

Yealy Previous Close

zigzag(7)

ZigZag

Technical Events

Event

Explanation

Formula sample

ca

Crossed Above

ema(7) ca ema(50)

cb

Crossed Below

ema(7) cb ema(50)

ia

Is Above

price ia ema(50)

ib

Is Below

price ib ema(50)

tocha

Touched Above

price tocha sma(50)

tochb

Touched Below

price tochb sma(50)

bon_up

Bounced Up From

price bon_up bblb(20,2)

bon_dn

Bounced Down From

price bon_dn bbub(20,2)

div_bull

Bullish Divergence

rsi(14) div_bull

div_bear

Bearish Divergence

rsi(14) div_bear

trend_up

Trending Up

price trend_up 7

trend_dn

Trending Down

price trend_dn 7

Function Example

Explanation

Stock universe

ticker(fb,aapl,msft)

The ticker function allows you to run the screener only on the ticker names specified as parameters. May not include more than 100 ticker names. Use the Watch List tool to run the screener on a larger ticker list.

exch(nyse,nasdaq)

You can specify one or more stock exchanges for screening. Only items from the following list can be used as parameters: nyse, nasdaq, otc, iex, tsx, tsxv, cse, lse, xetra, moex, tadawul, nse, bse, bm, ses, ise, hkse, shse, tse, asx, nzx.

[watch list name]

You can specify a pre-created watchlist as a stock universe. To do this, enclose the watchlist name in square brackets. You can select multiple watchlists by specifying their names, separated by commas: [watch list 1, watch list 2, watch list 3]

[portfolio name]

Likewise, the name of a pre-created trading portfolio can be used. It is also possible to narrow the selection to open positions only, for example, [portfolio name@active] or closed positions [portfolio name@closed]. You can specify several portfolios by listing their names separated by commas, for example, [portfolio name 1 @active, portfolio name 2 @closed, portfolio name 3 @all]

caps(large,mid)

Sets the market capitalization condition. Only items from the following list can be used as parameters: micro, small, mid, large. The market capitalization breakdown is as follows, micro: 0 - 150M, small: 150M - 500M, mid: 500M - 5B, large: above 5B

sector(energy,basic_materials)

Sets the sector condition. Only items from the following list can be used as parameters: energy, basic_materials, industrial_goods, conglomerates, consumer_goods, healthcare, financial, technology, services, utilities, real_estate.

industry(130,131,132)

Sets the industry condition. An industry code or a comma-separated list of industry codes is required as parameters. Please refer to the List of Industries help topic for more details.

index(spx,nasdaq100)

Sets the index membership condition. Only items from the following list can be used as parameters: dow, sp500, nasdaq, nasd100, ru1000, ru2000, ru3000, rumid, rumicro, tsx, ftse100, ftse250, ftseall, dax, asx50, asx200, hsi, sti, klci.

type(stock)

Sets the instrument type condition. Only two parameters are supported, stock and fund.

options(yes)

Allows specifying if a stock has options listed and tradable on a market exchange. Only two parameters are supported, yes and no.

commodity(metals,crude_oil,gas)

This function narrows screening to specified commodity market instruments. Only the following items can be used as parameters: metals, crude_oil, gas, agriculture.

aggregate(indexes)

This function narrows screening to financial world indexes. The only parameter indexes is supported.

Calendar functions

day(1)

Returns true if the current day of month equal to the parameter value. The parameter value must be in the range of 1..31

weekday(Sun)

Returns true if the current day of week equal to the parameter value. The parameter value must be in the range of Sun..Sat

month(Jan)

Returns true if the current month equal to the parameter value. The parameter value must be in the range of Jan..Dec

workingday(10)

Returns true if the current working day of month equal to the parameter value

workingdayleft(1)

Returns true if the remaining number of working days in the current month equal to the parameter value

hour(12)

Returns true if the current hour equal to the parameter value. The parameter value must be in the range of 9..15 for IEX exchange and in the range of 0..23 for Forex. Applicable for intraday periods only.

minute(30)

Returns true if the current minute of hour equal to the parameter value. Applicable for intraday periods only. Items from the list below can be used as parameters. For 5-minute periods: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55; For 15-minute periods: 0, 15, 30, 45; For 30-minute periods: 0, 30;

Aggregate functions

abs(rsi(14) - 50)

Returns the absolute (positive) value of an expression

max(rsi(14), 10)

Returns the maximum value of an expression for the specified number of days / bars

min(rsi(14), 10)

Returns the minimum value of an expression for the specified number of days / bars

avg(rsi(14), 10)

Returns the average value of an expression for the specified number of days / bars

count(rsi(14) < 30, 10)

Returns the number of days / bars for which the expression is true for the specified number of days / bars

change(10)

Returns the price % change over the specified number of days / bars

evalat(sma(21) - sma(7), 10)

Returns the value of the expression specified as the first parameter at the day/bar specified in the second parameter.
The expression in this example works the same way as historical screening "(sma(21) - sma(7))@10" but the second parameter can contain any arithmetic expression, for example:
evalat(sma(21) - sma(7), min(rsi(14), 7))

Highest and lowest prices

highest(10)

Returns the highest price over a specific number of days/bars

lowest(10)

Returns the lowest price over a specific number of days/bars

highestbar(10)

Returns the shift of the highest price over a specific number of days/bars

lowestbar(10)

Returns the shift of the lowest price over a specific number of days/bars

highestvol(10)

Returns the highest volume value over a specific number of days/bars

lowestvol(10)

Returns the lowest volume value over a specific number of days/bars

highestvolbar(10)

Returns the shift of the highest volume value over a specific number of days/bars

lowestvolbar(10)

Returns the shift of the lowest volume value over a specific number of days/bars

highestclose(10)

Returns the highest close price over a specific number of days/bars

lowestclose(10)

Returns the lowest close price over a specific number of days/bars

highestoc(10)

Returns the highest open or close price over a specific number of days/bars

lowestoc(10)

Returns the lowest open or close price over a specific number of days/bars

highestclosebar(10)

Returns the shift of the highest close price over a specific number of days/bars

lowestclosebar(10)

Returns the shift of the lowest close price over a specific number of days/bars

highestocbar(10)

Returns the shift of the highest open or close price over a specific number of days/bars

lowestocbar(10)

Returns the shift of the lowest open or close price over a specific number of days/bars

Candlestick functions

wick(0)

Returns the size of the "upper shadow" part of a candle. The parameter value is the shift relative to the current bar

tail(0)

Returns the size of the "lower shadow" part of a candle. The parameter value is the shift relative to the current bar

body(0)

Returns the size of the "real body" part of a candle. The parameter value is the shift relative to the current bar

crange(0)

The range the price moved during the time frame of the candlestick (high - low). The parameter value is the shift relative to the current bar

bmid(0)

The middle of the candlestick's "real body" (close + open) / 2. The parameter value is the shift relative to the current bar

tprice(0)

Returns the Typical Price value for a given bar: (high + low + close) / 3. The parameter value is the shift relative to the current bar

mprice(0)

Returns the Median Price value for a given bar: (high + low) / 2. The parameter value is the shift relative to the current bar

wprice(0)

Returns the Weighted Price value for a given bar: (high + low + 2 * close) / 4. The parameter value is the shift relative to the current bar

Math functions

math.max(ema(50), ema(200))

Returns the largest of two values passed to it as parameter

math.min(ema(50), ema(200))

Returns the smallest of two values passed to it as parameter

math.sqrt(rsi(14))

Calculates the square root of the parameter given to it

math.pow(rsi(14), 2)

The method returns the value of the first parameter raised to the power of the second parameter

math.round(rsi(14))

Rounds a floating point value to the nearest integer using normal math round rules (either up or down)

math.ceil(rsi(14))

Rounds a floating point value up to the nearest integer value

math.floor(rsi(14))

Rounds a floating point value down to the nearest integer value

correl(spy)

Returns the correlation coefficient between the specified ticker and the ticker that is checked against the screening criteria. For example, if we want to find all stocks whose correlation coefficient with the ticker SPY is more than 0.95, the formula expression will be correl(spy) > 0.95. The correlation will be calculated for the last 21 business days by default. You can change this period by setting the second parameter, for example: correl(spy,50) > 0.95.

Time-based functions

last_update()

Returns the number of minutes since the last stock quote update

sinceipo

Returns the number of days that have passed since the IPO day

Output instructions

sortby(rsi(7), desc, 10)

Instructs the Stock Screener to sort results by the specified indicator, financial metric or other parameter, using the ascending (asc) or descending (desc) order.
The third parameter indicates how many stocks to select after sorting. The second and third parameters are optional.
If the parameter indicating the sorting direction is not specified, then ascending order will be used.
If the third parameter is not specified, then after sorting all stocks will be selected.

show(rsi(14))

Instructs the Stock Screener to add the listed columns to the results page.
Columns will be added to the right of the standard columns of the stock screen and will display the corresponding values for each ticker.
The indicators listed in the show function will also be plotted on charts that are opened from the stock screen
and on mini charts when switching to the "Charts" view.
In this example, you can also set the column name as follows: show(rsi(14) as rsi)

draw(rsi(7), rsi(14))

Instructs the Stock Screener to draw the listed indicators on charts that are opened on the results page
and on mini charts when switching to the "Charts" view.

Historical screening

hist(12/31/2019)

Instructs the Stock Screener to perform historical screening. The screener will only select stocks that match the formula
expression as of the specified date. The date should be indicated in a short date format: month/day/year.

Price level functions

fibo23s(1)

Returns the value of the 23.6% Fibonacci retracement level. Fibonacci is applied to the first (nearest by registering date) recognized uptrend. Examples:
price cb fibo23s(1) - price crossed below the 23.6% fibo level.
price tocha fibo23s(1) - price touched above the 23.6% fibo level.
price bon_up fibo23s(1) - price bounced up from the 23.6% fibo level.
For 38.2%, 50.0%, 61.8% and 78.6% fibonacci levels, you can use the following functions: fibo38s, fibo50s, fibo62s, fibo78s.

fibo23r(1)

Returns the value of the 23.6% Fibonacci retracement level. Fibonacci is applied to the first (nearest by registering date) recognized downtrend. Examples:
price ca fibo23r(1) - price crossed above the 23.6% fibo level.
price tochb fibo23r(1) - price touched below the 23.6% fibo level.
price bon_dn fibo23r(1) - price bounced down from the 23.6% fibo level.
For 38.2%, 50.0%, 61.8% and 78.6% fibonacci levels, you can use the following functions: fibo38r, fibo50r, fibo62r, fibo78r.

snr_sup(9,1)

Returns the value of the first (nearest by registering date) support level of the SNR(9) indicator. Examples:
price cb snr_sup(9,1) - price crossed below the 1st support level of the SNR(9) indicator.
price tocha snr_sup(9,2) - price touched above the 2nd support level of the SNR(9) indicator.
price bon_up snr_sup(9,3) - price bounced up from the 3nd support level of the SNR(9) indicator.
You can also use snrc_sup and snroc_sup functions for accessing the support level of the SNRC(9) and SNROC(9) indicator correspondingly.

snr_res(9,1)

Returns the value of the first (nearest by registering date) resistance level of the SNR(9) indicator. Examples:
price ca snr_res(9,1) - price crossed above the 1st resistance level of the SNR(9) indicator.
price tochb snr_res(9,2) - price touched below the 2nd resistance level of the SNR(9) indicator.
price bon_dn snr_res(9,3) - price bounced down from the 3nd resistance level of the SNR(9) indicator.
You can also use snrc_res and snroc_res functions for accessing the resistance level of the SNRC(9) and SNROC(9) indicator correspondingly.

snr_minsup(9,50)

Returns the value of the lowest support level found using the SNR(9) indicator in the last 50 bars/days. Examples:
price cb snr_minsup(9,50) - price crossed below the value of the lowest support level found using the SNR(9) indicator in the last 50 bars/days.
You can also use the snr_minres function for accessing the lowest resistance level of the SNR(9) indicator.
Use snrc_minsup and snroc_minsup functions for accessing the lowest support level of the SNRC(9) and SNROC(9) indicator correspondingly.

snr_maxres(9,50)

Returns the value of the highest resistance level found using the SNR(9) indicator in the last 50 bars/days. Examples:
price ca snr_maxres(9,50) - price crossed above the value of the highest resistance level found using the SNR(9) indicator in the last 50 bars/days.
You can also use the snr_maxsup function for accessing the highest support level of the SNR(9) indicator.
Use snrc_maxres and snroc_maxres functions for accessing the highest resistance level of the SNRC(9) and SNROC(9) indicator correspondingly.

Williams' Fractals

frasup(2,2,1)

Returns the value of the first (nearest by registering date) lower fractal level of the Fractals(2,2) indicator. Examples:
price cb frasup(2,2,1) - price crossed below the 1st lower fractal level of the Fractals(2,2) indicator.
price tocha frasup(2,2,1) - price touched above the 1st lower fractal level of the Fractals(2,2) indicator.
price bon_up frasup(2,2,1) - price bounced up from the 1st lower fractal level of the Fractals(2,2) indicator.

frares(2,2,1)

Returns the value of the first (nearest by registering date) upper fractal level of the Fractals(2,2) indicator. Examples:
price ca frares(2,2,1) - price crossed above the 1st upper fractal level of the Fractals(2,2) indicator.
price tochb frares(2,2,1) - price touched below the 1st upper fractal level of the Fractals(2,2) indicator.
price bon_dn frares(2,2,1) - price bounced down from the 1st upper fractal level of the Fractals(2,2) indicator.

framinsup(2,2,50)

Returns the value of the lowest support fractal level found using the Fractals(2,2) indicator in the last 50 bars/days. Examples:
price cb framinsup(2,2,50) - price crossed below the lowest support fractal level found in the last 50 days.
You can also use the framinres function for accessing the lowest resistance fractal.

framaxres(2,2,50)

Returns the value of the highest resistance fractal level found using the Fractals(2,2) indicator in the last 50 bars/days. Examples:
price ca framaxres(2,2,50) - price crossed above the highest resistance fractal level found in the last 50 days.
You can also use the framaxsup function for accessing the highest support fractal.

framinsupbar(2,2,50)

Returns the shift of the lowest support fractal found using the Fractals(2,2) indicator in the last 50 bars/days. Examples:
framinsupbar(2,2,50) < 5 - the 50-day lowest support fractal was registered over the last 5 days.
You can also use the framinresbar function for accessing the shift of the lowest resistance fractal.

framaxresbar(2,2,50)

Returns the shift of the highest resistance fractal found using the Fractals(2,2) indicator in the last 50 bars/days. Examples:
framaxresbar(2,2,50) < 5 - the 50-day highest resistance fractal was registered over the last 5 days.
You can also use the framaxsupbar function for accessing the shift of the highest support fractal.

Backtesting aids

posprice

Formula expression can be used as a criteria for closing a position in the Strategy Backtest tool.
This can be done by ticking the "Set by a formula expression" option and assigning the corresponding formula expression.

You can get the value of the price at which the position was opened using the "posprice" literal.

posbar

You can get the index of the day/bar at which the position was opened using the "posbar" literal. It is typically used in data arrays: open, high, low, close, v.
For example, low[posbar] will give the low price of the day/bar at which the position was opened.

evalat

You can get the value of the indicator or expression at the moment the position was opened using the "posbar" literal and the "evalat" function.
For example, evalat(rsi(14), posbar) will give the value of the RSI(14) indicator recorded on the day the position was opened.

posage

You can get the number of days/bars elapsed since the position was opened.

stopat(psar(0.02,0.2))

Instructs the trading simulator to move the stop loss level to the specified value. As a parameter, you can specify an indicator,
function, or other formula expression that returns a numerical value.
For example: stopat(psar(0.02,0.2)), stopat(ema(7)), stopat(lowest(21)).
If the expression for closing a position has already been set, then the function must be added using the "or" operator.
For example: rsi(14) < 60 or stopat(psar(0.02,0.2)).
Please note that the "stopat" function is applied with a one day/bar delay. That is, stop loss is
calculated on the current day/bar but will be applied on the next day/bar.

takeat(bbub(20,2))

Instructs the trading simulator to move the take profit level to the specified value. As a parameter, you can specify an indicator,
function, or other formula expression that returns a numerical value.
For example: takeat(bbub(20,2)), takeat(1.5 * ema(50)), takeat(highest(21)).
If the expression for closing a position has already been set, then the function must be added using the "or" operator.
For example: rsi(14) > 75 or takeat(bbub(20,2)).
Please note that the "takeat" function is applied with a one day/bar delay. That is, take profit is
calculated on the current day/bar but will be applied on the next day/bar.

if(price > 1.05 * posprice, stopat(low[0]))

The IF function can be useful in the formula for closing a position in combination with the STOPAT or TAKEAT instructions.
In this formula, the stop loss will be set at the day's low level, but only if the position's profit is more than 5%.
If the expression for closing a position has already been set, then the function must be added using the "or" operator.
For example: rsi(14) < 60 or if(price > 1.05 * posprice, stopat(low[0]))