Adding Moving-Average Conditions to Backtest Sell Rules
Summary
This forum question concerns adding a moving-average exit condition to an AI stock-selection backtest. The proposed logic waits until a minimum holding period has passed, then examines positions in reverse StockRanker prediction order and sells eligible holdings when a short moving average falls below a longer one. The author’s attempt calls a mean method on an Equity asset and reports an attribute error, showing that an asset object does not itself provide the requested time-series calculation.
The document is a question rather than a resolved tutorial: it supplies neither a working correction nor evidence about the trading rule’s performance. It illustrates the distinction between an instrument identifier and historical price data needed to calculate indicators. The example also combines rank-based portfolio replacement with a moving-average filter, but leaves data retrieval, lookback availability, timing, and order handling unresolved. Any implementation would need to use the backtesting platform’s supported history or pipeline interface and guard against unavailable observations.
Key ideas
- The proposed exit logic begins after a specified holding period and ranks current holdings for possible sale.
- A short moving average below a longer one is intended to trigger a sale.
- The reported error occurs because the Equity asset object has no mean method.
- The post asks how to access moving-average values but provides no solution or performance evidence.
- Indicator calculations require historical price data through a supported backtest data interface.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.