Hyperliquid Moving Average Crossover Bot
An open-source moving average crossover bot for Hyperliquid perpetuals. It uses 15-minute candles, trades in asset units, requires the symbol to be flat on startup, and waits for the next crossover before opening risk.
What This Bot Actually Does
This strategy runs a simple moving average crossover on fixed 15-minute Hyperliquid candles. A fast SMA sits on top of a slower SMA, and the bot treats that as a long signal. When the fast SMA falls below the slow SMA, the bot treats that as a short signal.
The implementation is intentionally simple. It does not try to predict breakouts or adapt the timeframe dynamically. It just polls the latest 15-minute candles, computes the two averages, and flips the position when the crossover changes direction.
Position size is passed in asset units, not USD notional. If you run the bot with `--size 0.001` on BTC, that means 0.001 BTC of exposure, not a 1-dollar or 100-dollar order.
Startup And Execution Behavior
On startup, the bot requires the symbol to be flat. If you already have a live position in that market, it exits instead of taking over a manual trade. Once started flat, it records the current signal and waits for the next crossover before opening fresh risk.
After that, the bot only acts on real signal changes for positions whose live side and size still match the last trade it opened itself. If you manually change that position, the bot refuses to take it over and waits for you to flatten it. This keeps the behavior deterministic, but it also means fills are subject to slippage in fast markets.
The bot does not include a stop-loss or volatility filter. It is a trend-following example script, not a full execution stack with portfolio controls.
Parameters That Matter
The most important knobs are `--fast`, `--slow`, `--size`, and `--interval`. `--fast` and `--slow` are the number of completed 15-minute candles used for each moving average. `--interval` is only the polling cadence in seconds; it does not change the candle timeframe.
Shorter SMA pairs like 5/20 respond faster but whipsaw more. Wider pairs like 20/100 respond slower and can miss a chunk of the move before confirming. The right choice depends on the asset and how much chop you expect.
Because `--size` is in raw asset units, sizing discipline matters. The same number means very different risk on BTC versus ETH versus SOL.
When This Strategy Breaks
A moving average crossover performs best when price trends cleanly for long enough that the bot can stay with the move. It tends to perform worst when price chops sideways and the signal flips repeatedly without a real trend emerging.
That chop problem is not theoretical. The implementation uses market orders and has no protective stop logic, so repeated false flips can accumulate fees and slippage quickly.
Treat this as a transparent baseline strategy. It is useful because it is easy to inspect and modify, not because it solves every execution or risk problem out of the box.
Command-Line Arguments
| Flag | Description | Default |
|---|---|---|
| --symbol | Perp symbol | BTC |
| --fast | Fast SMA period in completed 15m candles | 10 |
| --slow | Slow SMA period in completed 15m candles | 30 |
| --size | Position size in asset units, not USD notional | 100 |
| --interval | Polling cadence in seconds | 60 |
Risk Warnings
- ■Whipsaws in sideways markets can stack fees and slippage quickly.
- ■The bot uses market orders for entries and exits, so fills can degrade in fast moves.
- ■There is no stop-loss or volatility filter in the execution path.
- ■The bot requires the symbol to be flat on startup and will refuse to manage a live position that was manually changed later.
- ■Sizing is in raw asset units, which is easy to misread if you are thinking in USD.
Get Started
Run the linked repo from its root with the exact entrypoint this strategy exposes.
1. Clone the repo
$ git clone https://github.com/atlasdetitan/hyperliquid-trading-bots.git
$ cd hyperliquid-trading-bots
2. Install dependencies
$ python3 -m pip install -r requirements.txt
3. Configure credentials
$ printf 'PRIVATE_KEY=0x...\\n' > .env
Generate an agent wallet at app.hyperliquid.xyz/API and set PRIVATE_KEY in .env. If you use an agent wallet, add ACCOUNT_ADDRESS for the authorizing main wallet.
4. Run the repo entrypoint
Live trading example
$ python3 strategies/ma_crossover/bot.py --symbol BTC --fast 10 --slow 30 --size 0.001 --interval 60
DEPLOY ON HYPERLIQUID
Run this bot on the fastest on-chain perpetuals exchange