Appearance
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 otherwiseParameters:
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:
| Date | RSI | Signal |
|---|---|---|
| Jan 3 | 48.2 | FLAT |
| Jan 4 | 51.7 | LONG |
| Jan 5 | 53.1 | LONG |
| Jan 6 | 49.8 | FLAT |
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 < MAParameters:
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:
| Date | OBV | OBV 20-day MA | Signal |
|---|---|---|---|
| Jan 3 | 1,240,000 | 1,180,000 | LONG (OBV > MA) |
| Jan 4 | 1,170,000 | 1,195,000 | FLAT (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 otherwiseParameters:
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):
| Date | ATR | 70th pct of past 252 ATRs | Signal |
|---|---|---|---|
| Jan 3 | 18.4 | 21.0 | FLAT (ATR below 70th pct) |
| Jan 4 | 24.1 | 21.0 | LONG (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
| Indicator | Recommended rule | Reason |
|---|---|---|
| RSI (0–100) | Threshold (50) | Natural midpoint separating up/down momentum |
| P/MA Ratio | Threshold (1.0) | Value of 1.0 means price = MA, natural neutral point |
| SMA/EMA Crossover | Threshold (0) | Positive = fast above slow, natural zero crossing |
| OBV | Crossover | Absolute OBV is meaningless; direction is what matters |
| ATR | Percentile | Absolute ATR values shift dramatically by regime |
| Volatility Ratio | Threshold (1.0) | Value of 1.0 = current vol equals long-term vol |
| Stochastic | Threshold (50) | Above 50 = closed in upper half of recent range |
| ADX | Threshold (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