Skip to content

Position Rules

A position rule is the logic that converts an indicator's numeric output into a binary decision: be long (invested) or flat (cash). MarketHeist supports three position rule types. Choosing the right rule depends on the nature of your indicator.


Threshold Rule

Logic: Go long when the indicator value exceeds a fixed threshold. Exit (go flat) when it falls below.

Position = LONG   if indicator_value > threshold
Position = FLAT   otherwise

Parameters:

  • threshold — the fixed value the indicator must exceed to trigger a long position.

When to use:

  • Indicators that have a meaningful absolute scale, or a known neutral value.
  • RSI: threshold = 50 means "go long when momentum is positive" (RSI above 50 = more up-days than down-days recently).
  • P/MA Ratio: threshold = 1.0 means "go long when price is above its moving average."
  • ADX: threshold = 25 means "go long only when trend strength is significant."

Example — RSI with threshold 50:

DateRSISignal
Jan 348.2FLAT
Jan 451.7LONG
Jan 553.1LONG
Jan 649.8FLAT

Pitfall: The threshold should be chosen based on the indicator's theoretical range, not by optimizing over historical data (that leads to overfitting). For RSI, 50 is a natural threshold rooted in the indicator's construction.


Crossover Rule

Logic: Go long when the indicator value crosses above its own moving average. Exit when it crosses below.

MA = rolling mean of indicator over lookback_window bars
Position = LONG   if indicator_value > MA
Position = FLAT   if indicator_value < MA

Parameters:

  • ma_window — the lookback period for the indicator's moving average.

When to use:

  • Indicators without a fixed, meaningful absolute scale — where the direction of change matters more than the absolute level.
  • OBV (On-Balance Volume): absolute OBV values are arbitrary; going long when OBV is above its own MA captures "OBV is trending up."
  • ADX: similarly, "ADX increasing" (above its own MA) may be more informative than a fixed threshold.
  • Any indicator where you want to capture momentum within the indicator itself.

Example — OBV crossover with 20-day MA:

DateOBVOBV 20-day MASignal
Jan 31,240,0001,180,000LONG (OBV > MA)
Jan 41,170,0001,195,000FLAT (OBV < MA)

Advantage over threshold: Self-adapting — the MA adjusts to the indicator's current level, so the rule works across different market regimes without re-tuning.

Pitfall: The crossover introduces its own parameter (MA window). Keep it simple: a 20–50 bar MA is a reasonable default for most indicators. Be careful not to over-optimize this parameter.


Percentile Rule

Logic: Go long when the indicator value is above the N-th percentile of its own recent history.

lookback_percentile = rolling percentile of indicator over lookback_window bars
Position = LONG   if indicator_value > Nth percentile of past lookback_window values
Position = FLAT   otherwise

Parameters:

  • percentile — the percentile threshold (0–100). E.g., 60 means "go long when the indicator is in the top 40% of its recent values."
  • lookback_window — how many bars of history to compute the rolling percentile over.

When to use:

  • Indicators that are strongly regime-dependent — meaning the "normal" range of the indicator shifts significantly over time.
  • Volatility-based indicators: ATR values in 2020 were 3–5× larger than in 2017. A fixed threshold for "high volatility" would never trigger in calm markets. A percentile rule adapts to current market conditions.
  • VWAP Deviation: the size of typical deviations varies by ticker and volatility regime.

Example — ATR percentile rule (70th percentile, 252-day lookback):

DateATR70th pct of past 252 ATRsSignal
Jan 318.421.0FLAT (ATR below 70th pct)
Jan 424.121.0LONG (ATR above 70th pct)

In this example: "go long when volatility is elevated relative to its recent history" — a contrarian or risk-on-during-vol-spikes strategy.

Advantage: Fully adaptive to the indicator's current distribution. The rule never becomes "stuck" at a level that was relevant 5 years ago.

Pitfall: Uses a rolling lookback, so the rule requires lookback_window bars of warm-up before generating signals. Also, percentile-based rules are sensitive to the lookback window choice — too short and the percentile is noisy; too long and it's slow to adapt.


Choosing the right rule

IndicatorRecommended ruleReason
RSI (0–100)Threshold (50)Natural midpoint separating up/down momentum
P/MA RatioThreshold (1.0)Value of 1.0 means price = MA, natural neutral point
SMA/EMA CrossoverThreshold (0)Positive = fast above slow, natural zero crossing
OBVCrossoverAbsolute OBV is meaningless; direction is what matters
ATRPercentileAbsolute ATR values shift dramatically by regime
Volatility RatioThreshold (1.0)Value of 1.0 = current vol equals long-term vol
StochasticThreshold (50)Above 50 = closed in upper half of recent range
ADXThreshold (25)Standard definition of "trending market"

TIP

When in doubt, start with the threshold rule using the indicator's natural neutral point. Use crossover when the absolute level is meaningless. Use percentile when the indicator's scale drifts significantly over time.


Further reading

  • Indicators — all built-in indicators and their characteristics
  • Custom Indicators — write your own indicator and choose its position rule

MarketHeist Backtest Engine