- Getting Started
- What is Investfly?
-
User Management
-
Market Analysis
-
Trading
-
Automated Strategies
-
Logical Expressions
- Custom Indicators
- Investfly SDK API Docs
Expression Builder
Read the Expression Overview if you haven't already. The Expression Builder is a UI component used to create logical expressions for automated trading, algorithmic trading, and trading strategies. These expressions are essential for defining criteria or conditions in screeners, alerts, and automated trades. Watch the video below to learn how to use the Expression Builder.
Filters and Filter Groups
An expression is built using filters and filter groups. A filter contains one or more criteria combined using a logical OR operator, such as:
MarketCap > 100B OR MarketCap < 100M
A Filter Group combines multiple filters using the AND operator, such as:
(MarketCap > 100B OR MarketCap < 100M) AND (LastPrice > 1)
The example above shows two filter groups. The first filter group ((MarketCap > 100B OR MarketCap < 100M)) has two filters, and the second filter group (LastPrice > 1) has one filter.
Adding or Removing Filters
In the Expression Builder, click the ‘+And Filter’ or ‘+OR’ buttons to add a filter group or filter, respectively. You can delete them by clicking the cross icon.
Building Expressions
To build an expression, you must add variables, constants, or operators.
-
Adding Indicator Variables
Add variables by first selecting the indicator you want and then configuring it. The text box supports auto-suggest, so you can either type some characters and select from the suggested list or click on the text box and scroll through all available indicators. We also have a full list of supported indicators published.
- Click on the text box. A list of all supported indicators and operators will appear.
- If you know the name of the indicator, start typing it, and suggestions will appear.
- If you do not know the name or the auto-suggestion did not work, scroll through all available indicators and find the one you want.
- Once selected, the configure indicator dialog will appear.
- Provide the requested parameters.
- Click Save.
Most indicators will have these standard parameters in common:
-
Name Parameter
This is the variable name that will be used and displayed in the expression. Give a short, meaningful, and unique name to your variable. The system will auto-generate the name based on the indicator and the parameter values you specify, but you can change it as desired.
-
Security Parameter
This represents the security for which this indicator with defined parameters will be computed. Normally, the security is derived from the context. For example, when this expression is used in a trade order, the security is the same security being traded. When this expression is used in a screener, the security is the same security being processed to determine if it meets the criteria. Hence, you will usually leave it blank. However, in some situations, especially when doing correlation trading, you may want to force a particular indicator to always evaluate for a specific security, regardless of the context it's applied. Here is a simple screener example that shows how useful it is:
Find all stocks whose last price is greater than today’s open price of AAPL.The expression for this will be: LastPrice > OpenPrice_AAPL. You must set the security to AAPL when configuring the second variable (OpenPrice_AAPL). If you don’t do that, the screener will return all stocks whose last price is greater than their own open price (which is not what you want).
-
Lookback Parameter
The lookback parameter allows you to reference previous values of the same indicator. The default lookback is zero, which means it's the current value. Normally, you will leave it as default. Sometimes, if you want to have criteria like finding stocks whose SMA5 is greater than SMA5 20 minutes ago, you will set lookback=20 to reference values 20 minutes ago, assuming you set the bar as daily bars. Lookback is dependent on the value of bar parameters. For example, if the indicator is configured for 1-DAY bar, lookback=2 means the value 2 days ago. Whereas, if the indicator is configured on a 5-MINUTE bar, lookback=2 means the value 10 minutes before. The value you specify for the lookback is the number of bars to look back.
-
Add Numeric Values
To add a numeric value:
- Scroll through the list and click on “Number”. Alternatively, enter the number (such as 2), and click on ‘Number’ when it appears in the auto-suggest menu.
- The configure numeric value dialog will appear.
- Provide the value and unit (B, M, K, %).
- Click Save.
-
Adding Operators
Select the operator from the list. We support mathematical operators (add, subtract, multiply, divide) and grouping operators (parenthesis).
- Scroll through the list and click on “Operator”. Alternatively, enter the operator (such as +), and click on ‘Operator’ when it appears in the auto-suggest menu.
- The configure operator dialog will appear.
- Provide the necessary details.
- Click Save.
Modifying Variables
After you have added expression items (variables, numeric values, etc.), you can modify them easily by clicking on the chip. The same dialog screen that you used to configure and add the indicator variable will reappear, and you can make any edits as necessary.
Deleting Variables
You can also delete variables by clicking the cross icon on the chip.