Capture medium-term BTC/USD trends using weekly MA7/MA25 crossovers, switching between 100% long and cash-only exposure at weekly closes.
## Strategy Overview
This playbook implements a classic dual moving average crossover system optimized for Bitcoin. The strategy captures medium-term trends by comparing short-term (MA7) and medium-term (MA25) moving averages on weekly timeframes.
## Trading Logic
**Entry Condition:** When MA7 crosses above MA25 (golden crossover) on weekly close, allocate 100% to BTC.
**Exit Condition:** When MA7 crosses below MA25 (death crossover) on weekly close, move to 100% cash position.
## Parameters
- **Trading Pair:** BINANCE_SPOT_BTC_USDT
- **Timeframe:** Weekly (1w) candles
- **Execution:** Every Sunday at 00:00 UTC
- **Initial Capital:** 1,000,000 USD
- **Warm-up Period:** 25 weeks for MA25 calculation
## Risk Management
The strategy inherently manages risk through:
- Trend-following approach (only long positions)
- Cash preservation during downtrends
- No leverage usage
from alva.core import Strategy, Signal
from alva.indicators import sma
class BTCMACrossover(Strategy):
"""Weekly MA7/MA25 crossover allocator for BTC"""
def __init__(self):
super().__init__(
symbol="BINANCE_SPOT_BTC_USDT",
interval="1w",
initial_capital=1_000_000
)
def compute_features(self, df):
df["ma7"] = sma(df["close"], 7)
df["ma25"] = sma(df["close"], 25)
df["ma7_prev"] = df["ma7"].shift(1)
df["ma25_prev"] = df["ma25"].shift(1)
return df
def generate_signal(self, df):
bullish_cross = (
(df["ma7_prev"] <= df["ma25_prev"]) &
(df["ma7"] > df["ma25"])
)
bearish_cross = (
(df["ma7_prev"] >= df["ma25_prev"]) &
(df["ma7"] < df["ma25"])
)
if bullish_cross.iloc[-1]:
return Signal.LONG, 1.0
elif bearish_cross.iloc[-1]:
return Signal.EXIT, 0.0
else:
return Signal.HOLD, None