/tradecraft:mean-reversion-enginefrom tradecraft
Provides mean reversion strategy templates including Bollinger bounce, RSI extreme fade, and Z-score reversion with regime guard. Only use in ranging market regimes.
Ships in tradecraft. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
import pandas as pd
import numpy as np
class MeanReversionEngine:
@staticmethod
def bollinger_bounce(df: pd.DataFrame, period: int = 20, std_mult: float = 2.0) -> dict:
"""Buy at lower band, sell at upper band. Classic range strategy."""
close = df["close"]
mid = close.rolling(period).mean()
std = close.rolling(period).std()
upper = mid + std_mult * std
lower = mid - std_mult * std
pct_b = (close - lower) / (upper - lower)
current = df.iloc[-1]
return {
"strategy": "bollinger_bounce",
"upper": round(upper.iloc[-1], 5),
"middle": round(mid.iloc[-1], 5),
"lower": round(lower.iloc[-1], 5),
"pct_b": round(pct_b.iloc[-1], 3),
"signal": "BUY (at lower band)" if pct_b.iloc[-1] < 0.05 else
"SELL (at upper band)" if pct_b.iloc[-1] > 0.95 else "WAIT",
"target": round(mid.iloc[-1], 5),
"stop": round(lower.iloc[-1] - (upper.iloc[-1] - lower.iloc[-1]) * 0.25, 5) if pct_b.iloc[-1] < 0.05
else round(upper.iloc[-1] + (upper.iloc[-1] - lower.iloc[-1]) * 0.25, 5),
}
@staticmethod
def rsi_extreme_fade(df: pd.DataFrame, period: int = 14,
oversold: float = 25, overbought: float = 75) -> dict:
"""Fade RSI extremes with divergence confirmation."""
close = df["close"]
delta = close.diff()
gain = delta.where(delta > 0, 0).rolling(period).mean()
loss = (-delta.where(delta < 0, 0)).rolling(period).mean()
rsi = 100 - (100 / (1 + gain / loss.replace(0, np.nan)))
# Divergence: price makes new low but RSI makes higher low (bullish)
price_lower = close.iloc[-1] < close.rolling(20).min().iloc[-5]
rsi_higher = rsi.iloc[-1] > rsi.rolling(20).min().iloc[-5]
bull_divergence = price_lower and rsi_higher and rsi.iloc[-1] < 40
price_higher = close.iloc[-1] > close.rolling(20).max().iloc[-5]
rsi_lower = rsi.iloc[-1] < rsi.rolling(20).max().iloc[-5]
bear_divergence = price_higher and rsi_lower and rsi.iloc[-1] > 60
return {
"strategy": "rsi_extreme_fade",
"rsi": round(rsi.iloc[-1], 1),
"oversold": rsi.iloc[-1] < oversold,
"overbought": rsi.iloc[-1] > overbought,
"bullish_divergence": bull_divergence,
"bearish_divergence": bear_divergence,
"signal": "BUY (oversold + divergence)" if rsi.iloc[-1] < oversold and bull_divergence
else "BUY (oversold)" if rsi.iloc[-1] < oversold
else "SELL (overbought + divergence)" if rsi.iloc[-1] > overbought and bear_divergence
else "SELL (overbought)" if rsi.iloc[-1] > overbought
else "WAIT",
"quality": "A+" if bull_divergence or bear_divergence else "B",
}
@staticmethod
def zscore_reversion(df: pd.DataFrame, lookback: int = 60,
entry_z: float = 2.0, exit_z: float = 0.5) -> dict:
"""Z-score based reversion with configurable thresholds."""
close = df["close"]
mean = close.rolling(lookback).mean()
std = close.rolling(lookback).std()
z = (close - mean) / std.replace(0, np.nan)
return {
"strategy": "zscore_reversion",
"z_score": round(z.iloc[-1], 3),
"mean": round(mean.iloc[-1], 5),
"signal": "BUY (z < -2)" if z.iloc[-1] < -entry_z
else "SELL (z > 2)" if z.iloc[-1] > entry_z
else "EXIT" if abs(z.iloc[-1]) < exit_z and abs(z.iloc[-2]) > exit_z
else "WAIT",
"target": round(mean.iloc[-1], 5),
"distance_to_mean_pct": round((close.iloc[-1] / mean.iloc[-1] - 1) * 100, 2),
}
@staticmethod
def scan_all(df: pd.DataFrame, symbol: str = "") -> dict:
return {
"symbol": symbol,
"bollinger": MeanReversionEngine.bollinger_bounce(df),
"rsi_fade": MeanReversionEngine.rsi_extreme_fade(df),
"zscore": MeanReversionEngine.zscore_reversion(df),
"WARNING": "Mean reversion ONLY works in ranging markets. Check regime first.",
}
Source: "Trading with Python: Simple Scalping Strategy" by CodeTrading (Jan 2024)
A practical M5 scalping implementation of mean-reversion with trend filter:
For full implementation details and Python code, see scalping-framework skill.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
mean-reversion, bollinger-bands, rsi, z-score, trading-strategies, regime-filter
npx claudepluginhub mahmoud20138/tradecraft --plugin tradecraft169 skills in this plugin
/agent-developmentThis skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins./agentic-storageAgentic storage architecture — persistent memory for AI agents using MCP, immutable versioning, sandboxing, and intent validation. Covers the stateless problem in LLM agents, RAG limitations (read-only), MCP protocol (JSON-RPC, resources, tools), storage safety layers, and agent file system design. Source: IBM Technology (Martin Keen), March 2026. Use this skill for "agentic storage", "agent memory", "persistent agent state", "MCP storage", "agent file system", "agent hard drive", "stateless agent problem", "agent work product", "immutable versioning", "agent sandboxing", "intent validation", "agent safety layers", "agent context window limits", "storage for AI agents", "agent persistence", "autonomous agent storage", "agent audit trail". Works with mcp-integration, trading-brain, agents, trade-psychology-coach.
Other plugins' skills for the same job