Signal to position: threshold, crossover and percentile rules

On this page

Key takeaways

  • An indicator only describes the market, for example how strong recent up days were. A position rule is the separate decision that turns that description into being invested or in cash, day by day.
  • A threshold rule compares the indicator with a fixed line. A crossover rule compares it with its own moving average, so it reacts to turns rather than levels. A percentile rule compares it with its own recent history, so the line moves as the indicator's normal range changes.
  • One indicator can produce very different strategies: one rule keeps a strategy invested most of the time and trades a few times a year, another holds it only on rare days, a third switches every few weeks.
  • Direction matters as much as the line. Being long while an indicator is high is a bet that strength continues; being long while it is low is a bet on a rebound.
  • In MarketHeist the rule is evaluated at each day's close, the position earns returns only after that close, and the strategy earns nothing while in cash.

Definition

A position rule turns an indicator's value on each bar into a position: long, fully invested, or flat, in cash. The three common forms compare the indicator with a fixed level (threshold), with its own moving average (crossover) or with its own recent distribution (percentile), and the choice changes how often a strategy trades and how much of the time it is invested, even when the indicator is the same.

Also known as: position rule, trading rule, threshold rule, crossover rule, percentile rule, indicator to trade, long or flat rule, entry and exit rules.

How it works

An indicator such as the RSI, the relative strength index, produces a number on every bar. A backtest needs something else: on each bar, is the strategy holding the asset or not? The position rule is the bridge between the two. MarketHeist keeps it separate from the indicator, so one indicator can be tested under several rules and the difference between them is visible.

A threshold rule draws a fixed line: long while the indicator is above it, or below it if the direction is reversed, and flat otherwise. It suits indicators with a natural scale. The RSI and the stochastic oscillator run from 0 to 100, Bollinger %B puts the bands at 0 and 1, and a moving-average ratio crosses 1 when the short average crosses the long one. Its weakness is that the line never moves: if an asset spends years with its indicator above the line, the rule spends years invested.

A crossover rule replaces the fixed line with a simple moving average of the indicator itself, so the question becomes whether the indicator has risen relative to its own recent average. It ignores the level and responds to turns, which usually makes it trade more often. Applied to the stochastic oscillator's %K with a three-bar average, it is exactly the classic rule of %K above %D.

A percentile rule compares the indicator with a chosen percentile of its own values over a lookback window, such as its median over the past year. The line adapts: in a calm stretch it sits low, in an excited one high. That makes one setting usable across assets and eras whose indicator ranges differ. The cost is a second setting, and a time in the market that the percentile largely fixes: above a rolling median, a rule is long roughly half the time whatever the market does.

A position rule is like a thermostat. The thermometer, the indicator, only reports the temperature; the thermostat setting decides when the heating runs, and the same thermometer heats a very different house depending on whether the setting is a fixed temperature, a change from the recent average, or a rank among recent days.

What happens after the rule matters as much. An optional regime filter can force the position to cash, for example while the price is below its 200-day average, and the result is then shifted forward by the execution delay, one bar by default, so a decision made with a day's close earns nothing until after that close. Stateful rules, such as buying when the RSI falls below 30 and holding until it rises above 70, need separate entry and exit triggers; the backtester's advanced mode provides them, and the lab here uses the single-rule form.

Formula

The three single rules (direction above)
pt={1st>Lt0otherwise,Lt={cthreshold1m∑k=0m−1st−kcrossoverQq(st−n+1,…,st)percentile
pₜ
the position decided at the close of bar t: 1 = long, 0 = flat
sₜ
the indicator's primary output on bar t (for example the RSI)
Lₜ
the line the indicator is compared with on bar t
c
the fixed threshold
m
the crossover rule's moving-average window, in bars, bar t included
n
the percentile rule's lookback, in bars, bar t included
Q_q
the q-th quantile of the values listed, with linear interpolation between ranks

With direction below, the comparison becomes sₜ < Lₜ. Both comparisons are strict, so a value exactly on the line is flat. Bars where the indicator or its line is not yet defined (warm-up) have no position at all rather than a flat one.

From position to return
rt=PtPt−1−1,rtstrat=pt−drt−κ|pt−d−pt−d−1|
Pₜ
the adjusted closing price of bar t (dividends reinvested)
rₜ
the asset's return over bar t, from the previous close to this close
d
execution delay in bars (1 by default)
κ
one-way transaction cost as a fraction (basis points divided by 10,000)
rₜˢᵗʳᵃᵗ
the strategy's return over bar t

With d = 1, the position decided at the close of bar t earns the return from that close to the next one. Out of the market the return is 0.

Worked example

SPY's daily bars from Oct 2006 to Sep 2026, 5030 trading days over about 20 years, with one indicator, the 14-day RSI, turned into a position by four different rules. No trading costs, cash earns nothing, and every position earns returns from the close that set it.

The threshold rule, long while the RSI was above 50, held SPY on 69.2% of days and completed 270 round trips, about 13.5 a year. The crossover rule, long while the RSI was above its own 20-day average, read the same indicator and traded more often: 388 round trips, 19.4 a year, invested on 54.2% of days.

The percentile rule, long while the RSI was above its median of the past 252 trading days, was invested on 50.1% of days. Over the window the RSI's own median was 57.00, above 50, so the fixed line kept the threshold rule in the market more often than the moving median did: a fixed line inherits an asset's long-run tilt, a percentile line removes it.

Reversing the direction changes the rule's character. Long only while the RSI was below 30, the oversold reading, the rule held SPY on 1.7% of days, in 42 trades that lasted 2.0 days on average, and 90.5% of those trades ended with a gain.

None of the four rules grew as fast as holding SPY: 4.3%, 3.2%, 3.4% and 3.7% a year, against 11.1%. Their worst declines from a peak were -44.1%, -51.0%, -35.7% and -11.5%, against -55.2%. Long stretches in cash that earns nothing cost growth; what the rule decides is when the strategy is out and how often it switches. This page is about the mechanics, not a verdict on the RSI; the RSI guide looks at the indicator itself.

Data through Sep 2026. Reproduce id 063bde8a932a4b0e (this guide, its lab setup and the data month).

Interactive lab

SPY's price with the days each rule was invested shaded, the RSI with the rule's line, and a table of time in the market, trades, growth, drawdown and Sharpe ratio for every rule against buy-and-hold. Change the rule, its line or direction, the RSI period, the delay, the cost or the fund.

SPY price with the days the base rule held itS&P 500, adjusted daily close, Oct 2006 to Sep 2026, log scale. Shaded: the 271 stretches the base rule held the fund (69% of 5030 days).$50$100$200$50020062011201620212026SPY adjusted closeHeld by the base rule
SPY on a log scale. Shaded: the days the base rule held the fund. Oct 2006 to Sep 2026.
RSI with the base rule's lineRSI on SPY, Oct 2006 to Sep 2026. The rule compares it with the fixed line 50.203040506070802006201120162021202650RSI
RSI and the line the base rule compares it with. Oct 2006 to Sep 2026.
Growth of $10,000: the setups against buy and holdS&P 500, Oct 2006 to Sep 2026, log scale. $10,000 grows to $23,157 (base), $18,802 (Crossover: RSI above its 20-day average), $19,634 (Percentile: RSI above its 252-day median), $20,607 (Threshold, reversed: RSI below 30), $82,292 (buy and hold).$10k$20k$50k20062011201620212026Base ruleCrossover: RSI above its 20-day averagePercentile: RSI above its 252-day medianThreshold, reversed: RSI below 30Buy and hold
Growth of $10,000 on a log scale, same days for every line. Oct 2006 to Sep 2026.
MeasureBaseCrossover: RSI above its 20-day averagePercentile: RSI above its 252-day medianThreshold, reversed: RSI below 30Buy and hold
CAGR4.3%3.2%3.4%3.7%11.1%
Volatility (annualized)11.0%12.0%9.6%6.8%19.4%
Maximum drawdown-44.1%-51.0%-35.7%-11.5%-55.2%
Sharpe ratio0.440.320.400.570.64
Sortino ratio0.600.440.541.29n/a
Growth of $10,000$23,157$18,802$19,634$20,607$82,292
Time in the market69.2%54.2%50.1%1.7%100.0%
Round trips27038829342n/a
Round trips per year13.519.414.72.1n/a
Win rate30.7%35.8%36.2%90.5%n/a
Average win4.0%2.7%2.4%2.1%n/a
Average loss-1.2%-1.2%-0.9%-1.7%n/a
Payoff ratio3.212.272.521.29n/a
Average days held12.97.08.62.0n/a
Expectancy per trade0.4%0.2%0.3%1.8%n/a
Profit factor, per day1.101.091.122.451.13
Profit factor, per trade1.431.271.4312.23n/a
Indicator, last day48.78948.78948.78948.789n/a
Indicator, 10th / 50th / 90th percentile39.753 / 56.997 / 69.70639.753 / 56.997 / 69.70639.753 / 56.997 / 69.70639.753 / 56.997 / 69.706n/a
Days the rule alone is long69.1%54.2%50.1%1.7%n/a

S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: RSI (period 14); long while the RSI is above 50; execution delay 1; cost 0 bps one way. Crossover: RSI above its 20-day average: RSI (period 14); long while the RSI is above its own 20-day average; execution delay 1; cost 0 bps one way. Percentile: RSI above its 252-day median: RSI (period 14); long while the RSI is above its 50th percentile of the past 252 days; execution delay 1; cost 0 bps one way. Threshold, reversed: RSI below 30: RSI (period 14); long while the RSI is below 30; execution delay 1; cost 0 bps one way.

Buy and hold, same daysValue
Largest one-day gain14.5% on 13 Oct 2008
Largest one-day loss-10.9% on 16 Mar 2020
CAGR without the 10 largest gains6.6%
CAGR without the 30 largest gains1.8%
CAGR without the 10 largest losses16.0%
CAGR without the 30 largest losses22.1%

The days replaced by 0 are the largest daily gains (or losses) of the window.

How MarketHeist computes it

Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.

ChoiceHow it is computedIn the code
DataDaily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has.
WindowThe worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days.
BacktestThe backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days.
Years and volatilityA year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252.
Indicator statisticsThe indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0.
Buy and holdThe fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds.
Threshold ruleLong (1) when the indicator's primary output is strictly above the threshold (direction above) or strictly below it (direction below), otherwise flat (0). Warm-up bars, where the indicator is not yet defined, get no position and are left out of every metric.generatePositionpackages/shared/engine/positions.ts
Crossover ruleThe line is a simple moving average of the indicator over ma_window bars, the current bar included, defined only once the window is full. Long when the indicator is strictly above (or below) that average.smapackages/shared/engine/utils.ts
Percentile ruleThe line is the rolling quantile of the indicator over lookback bars, the current bar included, at percentile ÷ 100, with linear interpolation between ranks (as pandas rolling quantile). Long when the indicator is strictly above (or below) it.rollingQuantilepackages/shared/engine/utils.ts
Long or flat onlySingle rules produce positions of 1 or 0: no short positions and no partial sizes. The advanced mode's entry and exit triggers hold a state between bars (enter on one condition, exit on another, with optional stops, time exits and partial sizes); that is how a band rule such as buy below 30, sell above 70 is built.generateTriggeredPositionpackages/shared/engine/triggered_position.ts
Order of operationsIndicator, then position rule (or entry and exit triggers), then the optional regime filter, which forces the position to 0 on bars that fail its condition. The resulting series is what the backtest shifts by the execution delay.computePositionpackages/shared/engine/run_basic.ts
Position to returnThe position series is shifted forward by the execution delay (1 bar by default) and multiplied by each bar's close-to-close return on adjusted prices; cash earns 0. Bars where the shifted position or the return is undefined are dropped. Transaction costs, when set, are charged on every bar where the shifted position changes.runBacktestpackages/shared/engine/backtest.ts
Engine functionsThe functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns.computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts

Signal to position (position rules) compared with its neighbours

Ways to turn an indicator into a position
RuleCompares the indicator withExtra settingTypical behaviour
ThresholdA fixed levelThe level and the directionTime in the market follows the indicator's long-run level; trades when the indicator crosses the line
CrossoverIts own simple moving averageThe average's windowReacts to turns, ignores the level; usually trades more often
PercentileA rolling percentile of its own valuesLookback and percentileAdapts to changing ranges; time in the market roughly set by the percentile
Entry and exit triggers (advanced mode)Separate conditions to enter and to leaveOne rule per side, optional stops and time exitsHolds a state between bars, as band rules such as RSI 30/70 need
Regime filterA second condition on the price (trend or volatility)The filter's window or levelOnly removes days from the position; never adds any

Limitations

  • One indicator, one fund, one window. How the rules differ here depends on how SPY's RSI behaved over these years; on an asset with a different range, the ranking of the rules can change.
  • Single rules are long or flat. They never sell short and never hold part of a position; stateful rules, partial sizes and stops need the advanced mode's entry and exit triggers.
  • The example charges no trading costs and pays no interest on cash. A rule that switches often pays more in costs, and cash earned interest in some of these years.
  • Every rule tried on the same history is another chance to find a pattern by luck. Choosing the rule after seeing its results is a form of overfitting, as the plateau test and walk-forward analysis explain.
  • Comparisons are strict and warm-up bars are excluded, so a value exactly on the line counts as flat and the first bars of a series, before the indicator and its line exist, are not counted as cash.

Frequently asked questions

What is the difference between a signal and a position?
A signal is the indicator's reading, a number such as an RSI of 62. A position is what the strategy holds as a result: invested or in cash. The position rule is the step in between, and changing it changes the strategy even when the signal is identical.
Which position rule fits which indicator?
Threshold rules suit indicators with a fixed scale, such as the RSI, the stochastic oscillator, Bollinger %B or a moving-average ratio around 1. Crossover rules suit indicators whose level drifts but whose turns matter. Percentile rules suit indicators whose normal range differs between assets or eras, such as volume or volatility measures. Any choice made after looking at the results is a selection and needs testing on data it did not see.
How do I backtest buying at RSI 30 and selling at RSI 70?
That rule has memory: between 30 and 70 it stays in whatever state it was in. A single threshold cannot express it, so it needs the backtester's advanced mode, with an entry trigger of RSI below 30 and an exit trigger of RSI above 70. The RSI 30/70 robustness page tests exactly that rule on five funds.
Why does the position start one bar after the signal?
Because the signal uses the bar's closing price, which is only known when the bar has ended. Letting it earn that same bar's return would be look-ahead bias. The execution delay guide shows how large that error can be.
Can a position rule go short?
Not in MarketHeist's backtester. Positions are long or flat, and with fractional entry triggers in the advanced mode, partly long; there is no short side.

References

  1. Wilder, J. W. (1978) New Concepts in Technical Trading Systems. Trend Research. The RSI and its overbought and oversold levels.
  2. Brock, W., Lakonishok, J. and LeBaron, B. (1992) Simple Technical Trading Rules and the Stochastic Properties of Stock Returns. Journal of Finance 47(5). Moving-average and trading-range rules as long or flat positions.
  3. Murphy, J. J. (1999) Technical Analysis of the Financial Markets. New York Institute of Finance. Oscillators, crossovers and their usual readings.

Try it on your own holdings

Open the backtester and switch the position rule →

Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:

Using MarketHeist.io, backtest the 14-day RSI on SPY daily bars with execution delay 1 under three position rules: long while RSI is above 50, long while RSI is above its 20-day average (crossover), and long while RSI is above its 252-day median (percentile). Compare time in the market, number of trades and CAGR with buy-and-hold.

Ask an AI assistant

The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.

Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: signal-to-position.md.