Add Supertrend and VWAP strategies plus a short-side example

- New indicators: vwap (rolling/cumulative) and supertrend (line + direction),
  exposed on StrategyContext.
- New strategies: supertrend (flip-based, optional shorts), vwap_reversion
  (mean reversion below a rolling VWAP) and ema_cross_short (short-side
  example, mirroring the long EMA cross). 10 strategies total.
- Adds indicator and strategy tests; smoke-tested all three on live BTC/USDT
  5m data.
This commit is contained in:
matitos committed 2026-09-22 14:14:12 +00:00
1 parent c1a7fb9c6b
commit d1f66c95c4
8 files changed
+420 -3

No files matched your search

+20 -1
View File
@@ -5,7 +5,17 @@ from collections.abc import Sequence
from dataclasses import dataclass
from typing import Any, ClassVar, Literal, Protocol
from app.engine.indicators import atr, ema, macd, roc, rolling_std, rsi, sma
from app.engine.indicators import (
atr,
ema,
macd,
roc,
rolling_std,
rsi,
sma,
supertrend,
vwap,
)
from app.models import PositionSide
from app.schemas import Candle, ParamSpec, StrategyOut
@@ -116,6 +126,15 @@ class StrategyContext:
def roc(self, period: int = 10) -> float | None:
return roc(self.closes, period)[-1]
def vwap(self, period: int | None = None) -> float | None:
return vwap(self._candles, period)[-1]
def supertrend(
self, period: int = 10, multiplier: float = 3.0
) -> tuple[float | None, bool | None]:
line, up = supertrend(self._candles, period, multiplier)
return line[-1], up[-1]
# --- order intents ------------------------------------------------
def enter_long(
self,