Investfly Query Builder

Investfly query builder can be used to craft both alerts and screens. The same queries will be applicable on both. Users can even import the screener query from alert builder and vice-versa. However there are certain rules for defining queries in our builder.


Rules to be followed while writing a Stock Screener Query:

  • A Stock Screener Query has one or more Screener Filters and each filter has one or more indicators.
    For example:
    (openprice > highprice) AND (lowprice < lastprice)

    Here,
    (openprice > highprice) is Filter 1
    (lowprice < lastprice) is Filter 2

  • These filters can be separated either by OR or by AND.
  • These indicators aren't any arbritary values but are Investfly Screener Indicators. The list of these supported indicators are given below.
  • Five categories of indicators available - Fundamentals, Stock Price, Trend, Momentum and Technicals.
  • You cannot compare indicators from incompatible categories, for example, Stock Price indicators are not compatible with Momentum indicators. So, openprice > rsi(10) is an invalid query.
  • There are indicators with periods, such as sma(5) and ema(14). The 5 and 14 refer to the period of the indicator. The period can be changed but only with values supported by Investfly. Additional details for periods supported for each indicator are located below.
  • Mathematical, Comparison and Logical operators can be used in combination to create a complex Stock Screener Query.
    For Example:
    (2 * sma(14) - ema(5) > ema(14)) AND (min(close, 5) > max(close, 14))

The categories and the indicators that can be used to create Stock Screener queries are listed below:

Fundamentals

Market Capitalization (marketcap)

Market Capitalization represents the total value of a company in the stock market and is calculated by total shares outstanding by the current price per share.

Sample Expression: marketcap > 100000000

Price-To-Earnings Ratio (pe)

Price-To-Earnings Ratio is the ratio of the stock price to the sum of its reported earnings.

Sample Expression: pe < 10

Price-To-Earnings-To-Growth Ratio (peg)

A stock's price/earning ratio divided by the growth rate of its earnings gives its Price-To-Earnings-To-Growth Ratio. It helps to determine a stock value by taking the company earning's growth into account.

Sample Expression: peg >= 30

Price-To-Sales Ratio (ps)

Price-To-Sales Ratio indicates value placed on each dollar of company's sales. It can be calculated by dividing company's close price by the annual sales per share.

Sample Expression: ps < 10

Price-To-Book Ratio (pb)

Price-To-Book ratio is used to compare a stock's market value to its book value. It is calculated by dividing the stock's current price by the latest quarter's book value per share.

Sample Expression: pb > 10 && pb < 30

EPS (eps)

EPS represents the company's net income allocated to each share as per the recent quarterly report. It serves as an indicator of a company's profitability.

Sample Expression: eps < 2

EPS Growth This Year (epsgrowththisyear)

EPS Growth This year is the EPS value of the current fiscal year.

Sample Expression: epsgrowththisyear > 20

EPS Growth Next Year (epsgrowthnextyear)

EPS Growth Next year is the EPS estimate for next fiscal year.

Sample Expression: epsgrowthnextyear < 30

Dividend Yield (dividendyield)

Dividend Yield represents how much a company pay in dividend each year relative to its share price. It measures how much you are getting for every dollar you invest in equity position. It is calculated by dividing the annual dividend per share by its stock price.

Sample Expression: dividendyield > 5%

Volume (volume)

Volume represents the latest number of stocks traded in the market.

Sample Expression: volume > 10000

Avg. Volume (avgvolume)

Avg. Volume represents the number of stocks traded over a time period, usually a year.

Sample Expression: avgvolume > 10000

Prev. Volume (prevvolume)

Prev. Volume represents the number of stocks traded in the previous trade day.

Sample Expression: prevvolume > 10000

Outstanding Shares

The company's shares that can be bought and sold freely without any restrictions by the public as well as number of shares hold by company insider (such as employees). Outstanding shares is float shares plus restricted shares.

Sample Expression: outstandingshares >= 50000

Return On Assets (returnonassets)

Return On Assets represents how profitable a company is relative to its total assets. It is calculated by dividing company's annual earnings by its total assets.

Sample Expression: returnonassets > 50%

Current Ratio (currentratio)

Current Ratio is a liquidity ratio that measures a company's ability to pay short-term obligations. It is calculated by divinding company's current assets by its current liabilities

Sample Expression: currentratio > 100

Debt/Equity (debt2equity)

Debt/Equity represents what proportion of equity and debt a company is using to finance its assets. It is calculated by dividing its total liabilities by its shareholder's equity

Sample Expression: debt2equity < 5

Operating Margin (operatingmargin)

Operating Margin measures a company's pricing strategy, what proportion of the company's revenue is left after paying for variable cost of production such as wages, raw materials, etc... It is calculated by dividing a company's operating income by its net sales.

Sample Expression: operatingmargin > 10.0

Forwarded PE (forwardpe)

Forwarded PE is the measure of the P/E ratio using forecasted earnings for the P/E calculation i.e. the value for next fiscal year. It is calculated by dividing market price per share by expected earnings per share.

Sample Expression: forwardpe > 10.0

Return On Equity (returnonequity)

Return On Equity measures how much profit a company makes with the amount share holders has invested. It is calculated as Net Income/Shareholder's Equity

Sample Expression: returnonequity > 10.0

Payout Ratio (payoutratio)

Payout Ratio is the percentage of earnings paid as dividends to shareholders.

Sample Expression: payoutratio > 50%

Insider Ownership (insideown)

Insider Ownership represents the level to which a company is owned by its own management.

Sample Expression: insideown > 10.0

Instituational Ownership (instown)

Instituational Ownership represents the level to which a company is owned by financial instituations.

Sample Expression: instown < 5.0

Profit Margin (profitmargin)

Profit Margin measures how much out of every dollar of sales a company actually keeps in earnings. It is calculated as net income divided by revenues, or net profits divided by sales.

Sample Expression: profitmargin >= 7.0

Qtrly. Earnings Growth (qtrlyearningsgrowth)

Qtrly. Earnings Growth is rate at which the company's earning has increased during the previous fiscal quarter. An increase is usually viewed as beneficial for a company.

Sample Expression: qtrlyearningsgrowth < 7.0

Beta (beta)

Beta is a measure of the stock price's volatility or a porfolio relative to the market. A positive beta means the assets follows the market and a negative beta means the assets inversely follows the market.

Sample Expression: beta < 7.0

EPS Surprise (epssurprise)

EPS surprise is a historical look at estimates versus the actual earnings in a given accounting period. A positive earnings surprise means a company did better than expected over the last quarter.

Sample Expression: epssurprise < 7.0

EPS Actual (epsactual)

EPS Actual referes to last quarter EPS, 12 month trailing EPS or last year EPS.

Sample Expression: epsactual >= 7.0

Avg. Eps Estimate (avgepsest)

An average of the EPS estimate made by analyst's for a company's future quarterly or annual earnings.

Sample Expression: avgepsest < 2.0

Avg. Rating (avgrating)

Avg. Rating also known as mean recommendation are rated on a scale of 1 to 5. It is an arithmetic average of analyst's buy-sell recommendation for a given stock.1 means a stock buy and 5 means a strong sale

Sample Expression: avgrating > 3.0 AND avgrating < 5.0

Rating Change (ratingchange)

Change in average rating from last week to this week.

Sample Expression: ratingchange < 5

Stock Price

Open Price (openprice)

Open Price is the price at which a stock was traded when the market opened on a given trading day.

Sample Expression: openprice > 100.0

High Price (highprice)

High Price is the maximum price at which a stock was traded on a given trading day.

Sample Expression: highprice > openprice

Low Price (lowprice)

Low Price is the minimum price at which a stock was traded on a given trading day.

Sample Expression: lowprice > openprice

Last Price (lastprice)

Last Price is the latest price at which a stock was traded.

Sample Expression: lastprice > openprice

Prev. Open (prevopen)

Prev. Open represents the open price of a stock prior its last trade day.

Sample Expression: prevopen > openprice

Prev. High (prevhigh)

Prev. High represents the high price of a stock prior its last trade day.

Sample Expression: prevhigh > highprice

Prev. Low (prevlow)

Prev. Low represents the low price of a stock prior its last trade day

Sample Expression: prevlow > lowprice

Prev. Close (prevclose)

Prev. Close represents the close price of a stock prior its last trade day

Sample Expression: prevclose > lastprice

High 52-Week (high52week)

High 52-Week represents the highest closing price in the last 52 weeks.

Sample Expression: high52week > highprice

Low 52-Week (low52week)

Low 52-Week represents the lowest closing price in the last 52 weeks.

Sample Expression: low52week < high52week

Max. Price (maxprice)

Max. Price represents the max of (high/low/close) price for the given period of time.

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: max(high, 5) > highprice

Min. Price (minprice)

Min. Price represents the min of (high/low/close) price for the given period of time.

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: min(close, 5) > lastprice

Trend

Simple Moving Average (sma)

A Simple Moving Average is calculated by adding the closing price of the security for a number of time periods and then dividing this total by the number of time periods.

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: sma(5) < sma(14)

Exponential Moving Average (ema)

Exponential Moving Average is similar to a simple moving average, except that more weight is given to the latest data. It is calculated as: Current ema =((Price (current)*alpha + (Previous ema*(1-alpha))

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: ema(5) > ema(14)

Moving Average Crossover Divergence (macd)

Moving Average Crossover Divergence is a trend-following momentum indicator that shows the relationship between two moving averages of prices. It is calculated by subtracting the n-period exponential moving average (ema) from the m-period ema.
It is represented as macd(m,n). A x(period) EMA of the MACD, called the "signal line", is then plotted on top of the macd, functioning as a trigger for buy and sell signals. This is represented as macd(m,n,x)

Supported Periods: (12,26), (20,50), (50,100), (100,200)
Sample Expression: macd(12,26) > macd(20,50)

Moving Average Crossover Divergence With Signal (macds)

MACD signal is “signal line” of x(period) EMA of the MACD,which is plotted on the top of the MACD, functioning as a trigger for buy and sell signals. This is represented as macd(m,n,x)

Supported Periods: (12,26,9), (20,50,12), (50,100,25), (100,200,50)
Sample Expression: macds(12,26,9) > macds(20,50,12)

Momentum

Relative Strength Index (rsi)

Relative Strength Index is a technical momentum indicator that compares the magnitude of recent gains to recent losses in an attempt to determine overbought and oversold conditions of an asset. It is calculated using the following formula:

RSI = 100 - 100/(1 + RS*)

where,
RS = Average of x days' up closes / Average of x days' down closes

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: rsi(30) < rsi(50)

Standard Deviation (stddev)

Standard Deviation measures the market volatility and characterizes the scale of price change relating to the Moving Average. Standard Deviation of a bar can be calculated as:

StdDev (i) = SQRT (AMOUNT (j = i - N, i) / N)

where,
StdDev (i) = Standard Deviation of the current bar
AMOUNT(j = i - N, i) = sum of squares from j = i - N to i;

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: stddev(30) < stddev(50)

William %R (willr)

Williams %R, or just %R, is a technical analysis oscillator showing the current closing price in relation to the high and low of the past N period (for a given N). The calculation involves:

%R = (Highest High - Close)/(Highest High - Lowest Low) * -100

where,
Lowest Low = lowest low for the look-back period(N days)
Highest High = highest high for the look-back period(N days)
%R is multiplied by -100 correct the inversion and move the decimal.

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: willr(30) < willr(50)

Commodity Channel Index (cci)

Commodity Channel Index is an oscillator to help determine when an investment vehicle has been overbought and oversold. It quantifies the relationship between the asset's price, a moving average (MA) of the asset's price, and normal deviations (D) from that average.

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: cci(150) < cci(200)

Stochastic Oscillator (stoch)

Stochastic Oscillator is a technical momentum indicator that compares a security's closing price to its price range over a given time period. Stochastic oscillator can be calculated as:

%K = 100[(C - L_period)/(H_period - L_period)]

where,
C = the most recent closing price
L_period = the low of the periods previous trading sessions
H_period= the highest price traded during the same given period.
%D = n-period moving average of %K

  1. Stochastic Oscillator Fast (stochf)
    Fast %K = n-period moving average of %K fast
    Supported Periods: (14,3)

  2. Stochastic Oscillator Slow (stochs)
    Slow %K =3-period moving average of %K fast
    Supported Periods: (14,3,3)

Sample Expression: stochf(14,3) < stochs(14,3,3)

Ultimate Oscillator (utl)

Ultimate Oscillator is the weighted average of three different time periods to reduce the volatility and false transaction signals that are associated with many other indicators that mainly rely on a single time period.

BP = Close - Minimum(Low or Prior Close)
TR = Maximum(High or Prior Close) - Minimum(Low or Prior Close)
Average7 = (7-period BP Sum) / (7-period TR Sum)
Average14 = (14-period BP Sum) / (14-period TR Sum)
Average28 = (28-period BP Sum) / (28-period TR Sum)

UO = 100 x [(4 x Average7)+(2 x Average14)+Average28]/(4+2+1)

Supported Periods: (7,14,28)
Sample Expression: utl(7,14,28) > stochs(14,3,3)

Percentage Price Oscillator (ppo)

Percentage Price Oscillator is a technical momentum indicator showing the relationship between two moving averages. It is calculated as:

ppo=(12 -day ema- 26-day ema) / 26-day ema

Supported Periods: (12,26)
Sample Expression: ppo(12,26) > utl(7,14,28)

Bollinger Bands (bband)

Bollinger Bands are volatility indicators that consist of:

  • an N-period moving average (ma)
  • an upper band at K times, an N-period standard deviation above the moving average (ma + Kσ)
  • a lower band at K times, an N-period standard deviation below the moving average (MA − Kσ)
Bandwidth tells how wide the Bollinger Bands are on a normalized basis. Writing the same symbols as before, and middleBB for the moving average, or middle Bollinger Band:
Bandwidth:=[ (ubband - lbband)/mbband]

where,
ubband = upper bollinger band lbbnad = lower bollinger band mbband = middle bollinger band

Supported Periods: (50,2.1), (10,1.9), (20,2)
Sample Expression: ubband(20,2) > lbband(20,2)

Median Price (medianprice)

Median Price is the mid point of the trading range for each period. It is calcualted as:

(High + Low ) / 2

Sample Expression: medianprice > 50

Typical Price (typicalprice)

Typical Price is another approximation of average price for each period and can be used as a filter for moving average systems. It is calculated as:

(High + Low + Close) / 3

Sample Expression: typicalprice < 50

Chande Momentum Oscillator (cmo)

Chande Momentum Oscillator is a technical momentum indicator created by calculating the difference between the sum of all recent gains and the sum of all recent losses and then dividing the result by the sum of all price movement over the period. The formula for cmo is derived as:

Cmo =100 x ( Su - Sd ) / ( Su + Sd )

where,
Su = sum of the momentum of up days in the period under analysis
Sd = sum of the momentum of down days in the period under analysis

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: cmo(30) > cmo(50)

Chande Momentum Oscillator-Smoothed (cmosmooth)

The CMO indicator calculated as above does not consider Wilder Smoothing. The formula for calculating smoothed cmo is:

CmoSmooth =100 x ( Avg1 - Avg2 ) / ( Avg1 + Avg2 )

where,
Avg1 = average of the momentum of up days in the period under analysis
Avg2 = average of the momentum of down days in the period under analysis

Sample Expression: cmosmooth(5) < cmosmooth(14)

Rate of Price Change (rocp)

Rate of Price Change is a price momentum indicator that measures percentage change between the most recent price and the price N periods ago. It is calculated as:

Rocp(n) = (Recent Price - Close Price N periods ago)/Close Price N periods ago

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: rocp(14) < 200

Technicals

Average Directional Index (adx)

Average Directional Index is a combination of two other indicators developed by Wilder, the positive directional indicator (abbreviated +DI) and negative directional indicator (-DI). The ADX combines them and smooths the result with an exponential moving average.
To calculate +DI and −DI, one needs price data consisting of high, low, and closing prices each period (typically each day). One first calculates the directional movement
(+DM and −DM):

  • UpMove = today's high − yesterday's high
  • DownMove = yesterday's low − today's low
if UpMove > DownMove and UpMove > 0, then +DM = UpMove, else +DM = 0
if DownMove > UpMove and DownMove > 0, then −DM = DownMove, else −DM = 0

After selecting the number of periods (Wilder used 14 days originally), +DI and −DI are:
  • +DI = 100 times exponential moving average of +DM divided by average true range
  • −DI = 100 times exponential moving average of −DM divided by average true range
The exponential moving average is calculated over the number of periods selected, and the average true range is an exponential average of the true ranges. Then,
ADX= 100 times the exponential moving average of the absolute value of (+DI − −DI) divided by (+DI + −DI)

Supported Periods: 5, 14, 30, 50, 100
Sample Expression: adx(30) < adx(50)

Average True Range (atr)

Average True Range is a technical analysis volatility that provides the degree of price volatility.The average true range is an N-day exponential moving average of the true range values, where

true range = max[(high-low), abs(high-close(prev)),abs(low-close(prev))]

Supported Periods: 5, 14, 30, 50, 100, 150, 200
Sample Expression: atr(30) < atr(50)

Price Change (pricechange)

Price Change is the difference between the previous close price and today's last price.

Sample Expression: pricechange > 100

Price Change Pct. (pricechangepct)

Price Change Pct is the difference between the previous close price and today's last price represeted in percentage

Sample Expression: pricechangepct < 10

Change Open (changeopen)

Change Open is the difference between stock's open price and last price on a given trading day.

Sample Expression: changeopen > 50