All Tools & Strategies

Hyperliquid Moving Average Crossover Bot

An open-source moving average crossover trading bot for Hyperliquid. Automatically detects trend shifts using configurable SMA periods and executes trades on the fastest on-chain perpetuals exchange.

Trend FollowingTechnical Analysis

What Is a Moving Average Crossover?

A moving average crossover is one of the oldest and most widely-used technical analysis signals. It compares two simple moving averages (SMAs) of different lengths — a "fast" average that reacts quickly to price changes and a "slow" average that smooths out noise over a longer window. When the fast MA crosses above the slow MA, it signals a potential uptrend. When it crosses below, it signals a potential downtrend.

This strategy works best in markets that exhibit clear, sustained trends. Perpetual futures on Hyperliquid are particularly well-suited because of 24/7 trading, tight spreads, and the ability to go both long and short with leverage. The crossover signal filters out short-term noise and keeps the bot positioned in the direction of the dominant trend.

Unlike discretionary trading, an automated crossover bot executes every signal without hesitation or emotional bias. It enters and exits positions the moment the mathematical condition is met, which is especially valuable in fast-moving crypto markets where a few seconds of delay can materially affect execution price.

How the Algorithm Works

The bot continuously polls the Hyperliquid API for the latest candlestick data at a configurable interval. On each poll cycle, it recalculates the fast and slow simple moving averages from the most recent closing prices. The fast SMA uses a shorter lookback window (default: 10 periods) while the slow SMA uses a longer one (default: 50 periods).

A buy signal is generated when the fast SMA crosses above the slow SMA — meaning the fast SMA was below the slow SMA on the previous candle and is now above it. Conversely, a sell signal fires when the fast SMA crosses below the slow SMA. On a buy signal the bot opens or increases a long position; on a sell signal it closes the long and optionally opens a short position.

Position sizing is configurable and the bot uses the Hyperliquid Python SDK to place market orders through an agent wallet. All orders are executed on-chain with the same security guarantees as manual trades. The bot logs every signal and execution for auditability.

Configuration Options

The bot accepts several command-line arguments that control its behavior. You can tune the fast and slow SMA periods, the trading symbol, position size, and the polling interval. All parameters have sensible defaults so you can start with zero configuration and refine from there.

For trending markets with strong momentum, shorter SMA periods (e.g., 5/20) generate more frequent signals. For less volatile markets or longer timeframes, wider periods (e.g., 20/100) reduce whipsaws at the cost of slower entries. The optimal configuration depends on the asset and market regime.

When It Works — and When It Doesn't

Moving average crossovers excel in trending markets. When an asset establishes a clear directional move, the bot rides the trend from early in the move until the trend reverses. The strategy is profitable whenever trend persistence exceeds the cost of false signals.

The strategy struggles in range-bound or choppy markets. When price oscillates around a narrow band, the fast and slow MAs cross repeatedly, generating a stream of losing trades (known as "whipsaws"). Each whipsaw costs a small amount in slippage and fees, which compounds over time.

For this reason, many traders combine the crossover bot with a volatility filter or use it only on assets that have historically demonstrated strong trending behavior. The open-source codebase makes it straightforward to add your own filters or conditions.

Command-Line Arguments

FlagDescriptionDefault
--symbolTrading pair symbolBTC
--fast-periodFast SMA lookback period10
--slow-periodSlow SMA lookback period50
--sizePosition size in USD100
--intervalCandle interval (e.g. 1m, 5m, 1h)5m

Risk Warnings

  • Whipsaws in sideways markets can erode capital through repeated small losses and fees.
  • Lagging indicator — the crossover confirms a trend after it has already started, meaning entries are never at the exact bottom.
  • No stop-loss by default. A sudden gap against your position can result in outsized losses, especially with leverage.
  • Past SMA period performance does not guarantee future results. Market regimes change.

Get Started

Deploy this strategy in under five minutes.

Setup
bash

1. Clone the repo

$ git clone https://github.com/atlasdetitan/hyperliquid-trading-bots.git

2. Install dependencies

$ cd strategies/ma_crossover

$ pip install -r requirements.txt

3. Configure your agent wallet

$ cp .env.example .env

Paste your agent wallet private key from app.hyperliquid.xyz/API

4. Run the bot

$ python main.py

DEPLOY ON HYPERLIQUID

Run this bot on the fastest on-chain perpetuals exchange