Skip to content

Strategies

Savvas Leousis edited this page Sep 26, 2026 · 2 revisions

Strategies

A strategy is a Python class that answers two questions each bar.

sequenceDiagram
  participant E as Engine or tick
  participant S as Strategy
  E->>S: estimate_return(ticker, as_of, lake)
  S-->>E: score, or None
  Note over E: keep tickers above threshold, rank them
  E->>S: decide(my_picks, portfolio, prices, as_of)
  S-->>E: list of orders
Loading
  • estimate_return: how good does this ticker look now? None means "no view".
  • decide: given my ranked picks and the portfolio, which orders to place? With a target-weight constructor the portfolio layer sizes the book instead (see Trading Tick).
  • parameter_spec() lists the knobs, their bounds and which are tunable. Tuners read only this.
  • fit() is optional (ML strategies train on the train window).
  • applicable_asset_classes limits which tickers a strategy sees (default equity).
  • Metadata such as hypothesis, alpha_family, label_horizon_bars and required_history_bars feed the lab (embargo, preflight) and the go-live checks.

Strategies read the lake only up to as_of, so they never see the future.

Catalog

These 28 ids work with stonks lab run <id>, stonks lab sweep, the API and MCP.

Reference and fundamentals

id Idea
buy_and_hold Buy one ticker once and hold it.
momentum Buy the best trailing return; sell holdings that drop out.
donchian_breakout Long above the recent high channel, flat below the low.
trendline_breakout Long when price breaks a fitted resistance line.
rsi_pca PCA over many RSI periods with a linear model (ML, uses fit).
quality_value Value and quality scores from statements, only after their filing_date.

From the books (details: Book Strategies)

id Idea
quant_momentum 12-2 momentum, top decile, smoothest paths, quarterly rebalance.
stocks_on_the_move Regression slope times R², trend and gap filters, ATR parity sizing.
quant_value EBIT/TEV value with forensic screens and quality ranks.
ewmac_trend Carver's moving-average crossover forecasts, volatility targeted.
tsmom Time-series momentum over 6 and 12 months.
ath_trend Buy weekly all-time highs, exit on a 10-ATR trailing stop.

neurotrader888 indicators

id Idea
ma_crossover Long while the fast moving average is above the slow one.
volatility_hawkes Long on a volatility breakout measured by a Hawkes process.
visibility_graph_path Long when the price visibility graph looks bullish.
vsa Volume spread analysis: range against volume.
market_profile_sr Trade breaks of support and resistance found by market profile.
intramarket_difference Trade one market on its trend relative to another.
tvl_deviation Crypto: long when price sits below its DeFi TVL trend line.

Patterns

id Idea
head_shoulders Long the inverse head and shoulders breakout.
flag_pennant Long the breakout of a bull flag or pennant.
harmonic_xabcd Long bullish harmonic patterns (Gartley, Bat, Crab, ...).
market_structure_break Long a break of market structure.

ML

id Idea
pip_miner Mines price patterns with k-means and trades the best cluster.
trendline_meta_label Trendline breakouts filtered by a random forest.

Wrappers (wrap any inner strategy)

id Idea
macro_regime_filter Trades only while a macro series says risk-on.
feature_regime_filter Goes flat when entropy, reversibility or runs say "unsafe".
last_trade_filter Takes an entry only after the last trade lost (or won).

Two more exist outside the catalog: TrailingStopWrapper (an ATR trailing stop around any strategy, used in code) and rule_based (the JSON-defined strategy of the Strategy Studio).

Details per family: docs/strategies/ in the repo.

Long-only

The broker cannot short yet. Sells are clipped to what you hold. Wherever an original strategy would go short, the Stonks version goes flat. Short selling is roadmap Phase 16.

Add your own strategy

  1. Write a failing test under tests/unit/.
  2. Add a module in src/stonks/strategies/examples/ (file name must not start with _).
from stonks.core.params import ParameterSpec
from stonks.strategies.base import BaseStrategy

class MyIdea(BaseStrategy):
    id = "my_idea"

    @classmethod
    def parameter_spec(cls):
        return [ParameterSpec(name="lookback", kind="int", default=20, bounds=(5, 100))]

    def estimate_return(self, ticker, as_of, lake):
        ...  # read bars with timestamp <= as_of, return a float or None

    def decide(self, my_picks, portfolio, prices, as_of):
        ...  # return a list of Order
  1. It appears in the catalog automatically. Run uv run stonks lab run my_idea --tickers ... --start ... --end ....

Clone this wiki locally