Strategy Library

Trading Strategies

Algorithmic strategies implemented from scratch in Python — each with a clear mathematical foundation, configurable parameters, and live backtesting.

Trend Following

Moving Average Crossover

A systematic trend-following strategy that utilizes three moving averages (20, 40, and 80 periods) to identify and capture sustained market trends across major indices such as Nifty 50, SPY, and Hang Seng Index. The strategy generates signals based on the relative position of price to all three moving averages, ensuring stronger trend confirmation and reducing false entries.

Long Entry — Price moves above all three MAs (20, 40, 80) → strong bullish trend
Long Exit  — Price falls below any of the three MAs → trend weakness
Short Entry — Price drops below all three MAs → strong bearish trend
Short Exit  — Price rises above any of the three MAs → possible reversal
Params: MA(20) · MA(40) · MA(80)
Mean Reversion

RSI Mean Reversion

Exploits the tendency of prices to revert to the mean after extreme moves. Buy when RSI drops below the oversold threshold (e.g. 30). Exit when RSI recovers above the overbought level (e.g. 70), take-profit is hit (+5%), or stop-loss is triggered (−2%).

BUY when RSI < oversold (default 30)
SELL when RSI > overbought (default 70)
     or Take Profit +5%  ·  Stop Loss −2%
Params: RSI period · Oversold · Overbought · TP% · SL%
Volatility

Bollinger Band Strategy

Uses dynamic bands that expand and contract with volatility. The upper and lower bands are set at N standard deviations from a rolling mean. Buy when price touches the lower band (oversold); sell when it touches the upper band (overbought).

BUY when price <= MA - N × σ
SELL when price >= MA + N × σ
Params: Window period, Std dev multiplier
Momentum

Momentum Strategy

Captures the empirically documented tendency for assets with strong recent performance to continue performing well. Buy when N-day return exceeds a threshold. Hold for a fixed period or exit when momentum reverses.

BUY when return(N) > threshold
SELL after {hold_days} OR return(N) < 0
Params: Lookback period, Hold days
Mean Reversion

Buy & Sell Next Day

A short-term mean reversion strategy that exploits oversold conditions. Buy at the open after N consecutive down-close days — a classic pullback signal. Exit at the next day's open (overnight hold) or same-day close (intraday).

BUY  at Open(N+1) after N consecutive down closes
SELL at Open(N+2)   — next day open exit
     OR Close(N+1) — same day close exit
Params: Consecutive down days, Exit type
Breakout

High / Low Price Breakout

A classic channel breakout strategy. Go long when price closes above the rolling N-day high — a signal of upside momentum. Exit when price falls below the rolling M-day low, protecting profits on the way down. Entry and exit periods are independently configurable for fine-tuned risk management.

BUY  when Close > highest High of last N days
SELL when Close < lowest Low  of last M days
Params: Entry period (N days), Exit period (M days)
Trend Following

Turtle Trading System

The legendary rule-based system taught by Richard Dennis in the 1980s. Enters long on N-day High breakouts and short on N-day Low breakdowns. Each trade is protected by an ATR-based Stop Loss and a 2× ATR Take Profit — capturing big trending moves while strictly controlling downside risk.

LONG when High > N-day High → SL: −sl×ATR  ·  TP: +tp×ATR
SHORT when Low  < N-day Low   → SL: +sl×ATR  ·  TP: −tp×ATR
Params: Channel periods · ATR period · SL/TP multipliers

Backtest Performance Metrics

Total Return
Cumulative % gain/loss over the backtest period.
Sharpe Ratio
Risk-adjusted return: mean return ÷ std dev × √252. Higher is better. >1 is good, >2 is excellent.
Max Drawdown
Largest peak-to-trough decline. Measures worst-case loss from a previous high.
Win Rate
% of completed trades that were profitable.
Number of Trades
Total round-trip (buy→sell) trade count over the period.
Final Value
Portfolio value at end of backtest given the initial capital.