Skip to main content
GlowBack includes a library of battle-tested trading strategies that you can use out-of-the-box or customize for your needs. All strategies implement the Strategy trait and support event-driven backtesting.

Available strategies

Buy and hold

Simple long-term investment strategy that purchases and holds assets

Moving average crossover

Trend-following strategy based on short and long-term moving averages

Momentum

Rides trends by measuring price momentum over a lookback period

Mean reversion

Statistical arbitrage strategy that trades price deviations from the mean

RSI

Oscillator-based strategy using Relative Strength Index

Common features

All built-in strategies share these capabilities:

Event-driven architecture

Strategies process market events in real-time and generate trading signals based on configurable parameters:
fn on_market_event(
    &mut self,
    event: &MarketEvent,
    context: &StrategyContext,
) -> Result<Vec<StrategyAction>, String>;

Configurable parameters

Every strategy accepts custom parameters through the StrategyConfig:
let mut config = StrategyConfig::new(
    "my_strategy".to_string(),
    "Custom Strategy".to_string()
);
config.set_parameter("position_size", 0.95f64);
config.add_symbol(symbol);

Position sizing

Control risk exposure with position size limits:
  • position_size - Percentage of capital to deploy (0.0 to 1.0)
  • max_position_size - Maximum position size cap (mean reversion only)

Performance metrics

All strategies track comprehensive performance metrics:
pub struct StrategyMetrics {
    pub total_return: Decimal,
    pub sharpe_ratio: Option<Decimal>,
    pub max_drawdown: Decimal,
    pub win_rate: Decimal,
    pub profit_factor: Decimal,
    // ... more metrics
}

Implementation details

Strategies are located in crates/gb-types/src/strategy.rs and implement the Strategy trait:
pub trait Strategy: Send + Sync {
    fn initialize(&mut self, config: &StrategyConfig) -> Result<(), String>;
    fn on_market_event(&mut self, event: &MarketEvent, context: &StrategyContext) -> Result<Vec<StrategyAction>, String>;
    fn on_order_event(&mut self, event: &OrderEvent, context: &StrategyContext) -> Result<Vec<StrategyAction>, String>;
    fn on_day_end(&mut self, context: &StrategyContext) -> Result<Vec<StrategyAction>, String>;
    fn on_stop(&mut self, context: &StrategyContext) -> Result<Vec<StrategyAction>, String>;
    fn get_config(&self) -> &StrategyConfig;
    fn get_metrics(&self) -> StrategyMetrics;
}

Quick start example

Here’s how to use a built-in strategy:
use gb_types::strategy::{MovingAverageCrossoverStrategy, StrategyConfig};
use gb_types::market::Symbol;

// Create strategy
let mut strategy = MovingAverageCrossoverStrategy::new(10, 20);

// Configure
let mut config = StrategyConfig::new(
    "ma_crossover".to_string(),
    "My MA Strategy".to_string()
);
config.add_symbol(Symbol::equity("AAPL"));
config.set_parameter("position_size", 0.90f64);

// Initialize
strategy.initialize(&config)?;

Next steps

Create custom strategies

Learn how to build your own trading strategies

Backtest strategies

Run backtests with built-in strategies

Build docs developers (and LLMs) love