Skip to content

Multi-Instrument Strategies

Stratifyre lets you apply a single strategy to hundreds of instruments at once. Instead of creating separate strategies for AAPL, MSFT, GOOGL, and so on, you define your rules once and Stratifyre evaluates them independently for every symbol in your selection.

This is how portfolio-level strategies, basket trading, and diversified automated systems work on the platform.

When you add multiple instruments to a strategy, Stratifyre does the following:

  1. Evaluates your rules for each instrument independently. If you have 100 symbols, each one gets its own evaluation cycle on every bar. A buy signal for AAPL does not affect the evaluation for MSFT.
  2. Maintains separate positions for each instrument. You can be long AAPL and short TSLA at the same time within the same strategy.
  3. Tracks performance both per-instrument and at the portfolio level. You can see how each symbol is contributing to the overall strategy result.

This means you write your rules in general terms – for example, “buy when RSI drops below 30” – and the platform applies that logic to every instrument you have selected. No need to hard-code ticker symbols into your rules.

Current instrument vs. explicit instrument references

Section titled “Current instrument vs. explicit instrument references”

Most multi-instrument rules run in a current-instrument context. In an all scoped rule, Stratifyre evaluates instrument A, then instrument B, then instrument C, and so on. During each pass:

  • price, close, position.*, and vars.* refer to the instrument currently being evaluated
  • bars['5m'] means “5-minute bars for the instrument currently being evaluated”
  • bars['<InstrumentId>~<Interval>'] lets you pull bars from a different instrument explicitly

Examples:

Expression Meaning
bars['15m'].close Current 15-minute close for the instrument currently being evaluated
bars['D'].close[1] Previous daily close for the instrument currently being evaluated
bars['EQ:NASDAQ:QQQ~1h'].close[1] Previous hourly close for QQQ
bars['EQ:NASDAQ:QQQ~D'].high[1] Previous daily high for QQQ

Portfolio-level none scoped rules do not have an implicit current instrument. If a portfolio rule needs instrument bar data, use the explicit InstrumentId~Interval form.

In the strategy builder’s Instruments section, search for symbols by ticker, name, or exchange. Select as many as you need.

Stratifyre includes pre-built instrument baskets that you can add with a single click:

Basket What it includes
S&P 500 All current constituents of the S&P 500 index
NASDAQ 100 All current constituents of the NASDAQ 100 index
Crypto 100 The top 100 cryptocurrencies by market capitalization
Dow Jones 30 All 30 components of the Dow Jones Industrial Average

Baskets are maintained and updated automatically. When index constituents change (for example, a company is added to or removed from the S&P 500), the basket updates accordingly.

Create your own instrument groups by clicking Create Custom Basket:

  1. Give your basket a name (for example, “Tech Leaders” or “Energy Sector”).
  2. Search for and add the symbols you want.
  3. Save the basket for reuse across multiple strategies.

Custom baskets are especially useful for sector-based strategies, watchlist-based approaches, or any situation where you want to trade a specific, curated group of instruments.

When a strategy trades multiple instruments, you often need variables that are scoped correctly. Stratifyre offers two types:

Local variables are unique to each instrument. If your strategy trades AAPL and MSFT, setting vars.entryPrice for AAPL does not affect vars.entryPrice for MSFT.

Use local variables for:

  • Tracking the entry price of each individual position
  • Storing per-instrument stop-loss or take-profit levels
  • Counting trades for a specific symbol
  • Recording the last signal direction for each instrument

Example: When an entry rule fires for AAPL, a Set Variable action stores vars.entryPrice = price. Later, an exit rule checks price > vars.entryPrice * 1.05 (5% profit target). This works correctly because each instrument has its own vars.entryPrice.

Global variables (shared across instruments)

Section titled “Global variables (shared across instruments)”

Global variables are shared across all instruments in the strategy. When any instrument updates a global variable, the new value is visible to all instruments on subsequent evaluations.

Use global variables for:

  • Tracking the total number of open positions across the portfolio
  • Enforcing a portfolio-wide risk budget (for example, “do not open new positions if we already have 10 open”)
  • Implementing cross-instrument signals (for example, “if SPY drops 2% today, stop buying individual stocks”)
  • Counting total trades taken across all instruments

Example: An entry rule has a condition that checks globals.openPositionCount < 10 before opening a new position. Whenever a position is opened, a Set Variable action updates globals.openPositionCount = globals.openPositionCount + 1. When a position is closed, another rule decrements the counter.

When trading many instruments with one strategy, position management becomes especially important. Here are common approaches:

Limit the total number of open positions at any time to manage capital allocation and risk.

How to set it up:

  1. Create a global variable called openPositionCount.
  2. In every entry rule, add a condition: globals.openPositionCount is less than your maximum (for example, 10).
  3. When a new position is opened, use a Set Variable action to increment: globals.openPositionCount + 1.
  4. When a position is closed, decrement: globals.openPositionCount - 1.

Divide your capital equally among all instruments that signal an entry.

Position sizing expression:

account.equity / 20 – If you want to hold a maximum of 20 positions, each position gets 5% of equity.

Or adapt dynamically:

account.equity / globals.maxPositions

Allocate capital based on each instrument’s volatility so that riskier instruments get smaller positions.

Position sizing expression:

(account.equity * 0.01) / ATR(14) – Risk 1% of equity per trade, with stop distance equal to one ATR. High-volatility instruments automatically get fewer shares.

Use global variables to track how many positions you have in each sector or correlated group, preventing over-concentration.

Example: Create global variables like globals.techCount, globals.energyCount, etc. Increment them when you open a position in each sector, and add conditions to your entry rules that cap each sector (for example, globals.techCount < 5).

Global variables let one instrument’s behavior influence decisions for others. This is useful for market-regime detection and portfolio-level risk management.

Use a broad market index as a filter for individual stock trades:

  1. Add SPY (or another benchmark) to your instrument list.
  2. Create a rule that checks whether SPY’s price is above its 200-day SMA.
  3. Use a Set Variable action to store the result in a global variable: globals.marketBullish = 1 (or 0 if bearish).
  4. In every other instrument’s entry rule, add a condition: globals.marketBullish == 1.

Now your strategy only buys individual stocks when the broad market is in an uptrend.

If you want to reference another instrument’s bars directly instead of routing through a global variable, use explicit syntax such as bars['EQ:NASDAQ:QQQ~D'].close[1].

Automatically reduce exposure when the market shows stress:

  1. Monitor a volatility index (like VIX) or a drawdown metric.
  2. When the risk-off condition is detected, set a global variable: globals.riskOff = 1.
  3. Add a condition to your entry rules: globals.riskOff == 0 (only allow new entries when risk is on).
  4. Optionally, create a rule that reduces position sizes or closes positions when globals.riskOff == 1.

Trade the strongest instruments from a basket and rotate periodically.

Concept:

  • Rank instruments by a momentum metric (for example, 3-month Rate of Change).
  • Buy the top N instruments.
  • At the end of each period (weekly or monthly), re-rank and rotate: sell instruments that have fallen out of the top N and buy the new entrants.

Implementation approach:

  • Use ROC or RSI on a weekly or monthly timeframe as your ranking indicator.
  • Set execution frequency to “Once per period” (for example, once per week).
  • Use global variables to track how many positions are open.

Trade the spread between two correlated instruments.

Concept:

  • Monitor the price ratio or spread between two instruments (for example, AAPL and MSFT).
  • When the spread widens beyond its historical average, go long the underperformer and short the outperformer.
  • Exit when the spread returns to normal.

Implementation approach:

  • Use global variables to store the spread or ratio.
  • Create entry rules that detect when the spread exceeds a threshold (for example, 2 standard deviations from the mean).
  • Create exit rules for when the spread normalizes.

Apply a breakout strategy across an entire basket and only trade the instruments that break out first.

Concept:

  • Monitor all instruments in a basket for a breakout above their Donchian Channel or previous-day high.
  • Only take the first N breakouts per day (to manage capital).

Implementation approach:

  • Use a global variable to track how many breakout entries have been taken today.
  • Use “Once per period” (daily) execution frequency on entry rules.
  • Add a condition that checks the global counter against your maximum.
  • Use risk-based position sizing. When trading many instruments, fixed-size positions can lead to wildly different risk levels across the portfolio. ATR-based or volatility-adjusted sizing keeps risk consistent.
  • Set a maximum number of concurrent positions. Without a cap, a multi-instrument strategy in a strong trending market could try to open positions in every single instrument at once, consuming all available capital.
  • Monitor correlation. Ten positions in highly correlated tech stocks is not true diversification. Consider adding conditions that limit exposure to correlated instruments or sectors.
  • Account for transaction costs. Trading 100 instruments means 100 entry and 100 exit transactions. Make sure commissions and slippage are accounted for in your backtests.
  • Use global variables sparingly. They are powerful but can make strategies harder to debug. Keep global variable logic as simple as possible, and always test that counters increment and decrement correctly.