Files
ai/gateway/knowledge/trading/strategies/stocks/single-moving-average.md
Tim Olson 47471b7700 Expand model tag support: add GLM-5.1, simplify Anthropic IDs, scan tags anywhere in message
- Flink update_bars debouncing
- update_bars subscription idempotency bugfix
- Price decimal correction bugfix of previous commit
- Add GLM-5.1 model tag alongside renamed GLM-5
- Use short Anthropic model IDs (sonnet/haiku/opus) instead of full version strings
- Allow @tags anywhere in message content, not just at start
- Return hasOtherContent flag instead of trimmed rest string
- Only trigger greeting stream when tag has no other content
- Update workspace knowledge base references to platform/workspace and platform/shapes
- Hierarchical knowledge base catalog
- 151 Trading Strategies knowledge base articles
- Shapes knowledge base article
- MutateShapes tool instead of workspace patch
2026-04-28 15:05:15 -04:00

58 lines
3.0 KiB
Markdown

---
description: "Generates long/short signals for a stock when its current price crosses above or below a single moving average, used as a trend-following entry and exit rule."
tags: [stocks, trend-following, moving-average, technical-analysis]
---
# Single Moving Average
**Section**: 3.11 | **Asset Class**: Stocks | **Type**: Trend-Following / Technical Analysis
## Overview
This strategy generates buy and sell signals based on whether the current stock price is above or below a single moving average (MA). If the price is above the MA, the stock is in an uptrend and a long position is established; if below, a downtrend is indicated and a short position is established. It can be applied on a single-stock basis or across a universe of stocks simultaneously.
## Construction / Signal
Two types of moving averages:
**Simple Moving Average (SMA)**:
```
SMA(T) = (1/T) * sum_{t=1}^{T} P(t) (319)
```
**Exponential Moving Average (EMA)**:
```
EMA(T, lambda) = (sum_{t=1}^{T} lambda^{t-1} P(t)) / (sum_{t=1}^{T} lambda^{t-1})
= ((1-lambda)/(1-lambda^T)) * sum_{t=1}^{T} lambda^{t-1} P(t) (320)
```
where `t=1` is the most recent day, `T` is the MA length (in trading days), and `lambda < 1` suppresses past contributions. For T >> 1: `EMA(T, lambda) ≈ (1-lambda) P(1) + lambda EMA(T-1, lambda)`.
**Trading signal** (P is the current price at t=0):
```
Signal = { Establish long / liquidate short position if P > MA(T)
{ Establish short / liquidate long position if P < MA(T) (321)
```
## Entry / Exit Rules
- **Long entry**: Current price P crosses above MA(T) → establish long position.
- **Long exit**: Current price P crosses below MA(T) → liquidate long position.
- **Short entry**: Current price P crosses below MA(T) → establish short position.
- **Short exit**: Current price P crosses above MA(T) → liquidate short position.
## Key Parameters
- **MA type**: SMA or EMA
- **MA length T**: Typically 50, 100, or 200 trading days (longer = slower, fewer signals)
- **Lambda (EMA only)**: Decay factor, 0 < lambda < 1; smaller lambda = faster decay
- **Run mode**: Long-only, short-only, or both long and short
## Variations
- **Multi-stock application**: Apply to a large universe of stocks on a single-stock basis; with many stocks, (near-)dollar-neutral portfolios can be constructed
- **Two moving averages**: See Section 3.12 (replace price P with a shorter MA)
- **Three moving averages**: See Section 3.13
## Notes
- Single-stock technical analysis strategies are considered "unscientific" by many academics, as there is no fundamental reason why a price crossing a moving average should have forecasting power.
- However, trend-following/momentum strategies (which use MAs to compute expected returns) are broadly used and empirically validated.
- Applicable on a single-stock basis with no cross-sectional interaction between stocks.
- With a large universe, near-dollar-neutral portfolios are achievable.
- The strategy can be run as long-only, short-only, or long-short.