Grid Trading Bot — User Guide
A browser-based tool for designing a grid trading strategy and shipping it straight to QuantConnect as a ready-to-backtest LEAN algorithm.
If you've used the Binance Futures Grid Bot before, the configuration here should feel familiar. The difference: instead of running live on Binance, your bot runs as a backtest on QuantConnect's historical data, so you can measure how your grid would have performed before risking real capital.
What is a grid bot?
A grid bot places a ladder of buy and sell limit orders across a fixed price range. Every time price oscillates between two grid levels, the bot captures the spread. The more price chops sideways inside your range, the more profit it books. If price leaves your range, grid trading stalls — so choosing the range is the most important decision you'll make.
Quick start
- Pick Futures or Spot mode at the top.
- Fill in Symbol, Lower Price, Upper Price, Number of Grids, and Investment.
- Watch the Profit/Grid, Qty/Order, and (for futures) Est. Liq. Price update as you type — these are computed live.
- Set your Backtest Settings (start/end date, resolution, initial cash).
- Click Download Script to grab the generated LEAN
.pyfile, or connect to QuantConnect below and click Deploy to QuantConnect to push it directly into your QC account.
That's the whole loop.
Configuration fields
Trading mode
- Futures — uses leveraged perpetual-style positions. Unlocks leverage selection, margin mode, and liquidation price estimate.
- Spot — 1:1 holdings. No leverage, no liquidation risk.
Symbol
The trading pair, e.g. BTCUSDT, ETHUSDT. Must exist on the venue your LEAN algorithm targets. Defaults to BTCUSDT.
Price range (Lower / Upper)
The boundaries of your grid. Grid levels are spread between these two prices. Price outside this range = no trading activity, so pick a range you believe price will spend most of its time inside during the backtest window.
Number of Grids (2–169)
How many levels to place between the lower and upper price. More grids = smaller profit per trade, but more trades. Fewer grids = larger profit per trade, but fewer opportunities.
Grid Spacing
- Arithmetic — equal price distance between every level. Best for ranges where price moves in absolute terms.
- Geometric — equal percentage distance between every level. Best for wide ranges or crypto, where percentage moves matter more than dollar moves.
Profit/Grid (read-only)
The per-trade profit percentage after fees are deducted. Calculated from your price range, grid count, spacing mode, and fee rate. If this shows a negative number, your fees are eating your spread — widen your range, reduce grids, or lower fees.
Investment (Margin)
The cash you're committing to the strategy. In futures mode this is margin; total notional position size is Investment × Leverage.
Leverage (futures only)
1x through 125x. Higher leverage amplifies both profit and liquidation risk. Watch the Est. Liq. Price as you change this — if the liquidation price enters your grid range, one sharp move will wipe the position.
Fee Rate (%)
The per-fill trading fee. Used when computing Profit/Grid. Defaults to 0.1 (10 bps, typical retail taker).
Margin Mode (futures only)
- Isolated — losses capped at the investment you allocated to this position.
- Cross — losses can eat into other balances in the same account.
Qty/Order (read-only)
The size of each individual grid order, computed from your investment and grid count.
Est. Liq. Price (read-only, futures only)
Estimated liquidation price at current settings. This is a rough estimate — the exact liquidation depends on your exchange's maintenance margin rules and any unrealized PnL.
Advanced options
Click Advanced (Optional) to expand.
Trailing Up
When enabled, the upper bound of the grid "trails" price upward as the market rallies, keeping the grid active even if price breaks out above the original range. Optional Upper Limit caps how high it can trail.
Trailing Down
Mirror of Trailing Up — the lower bound follows price down during a selloff. Optional Lower Limit caps how far it can trail.
Grid Trigger
Delays grid activation until price crosses a specified Trigger Price. Useful if you want the grid to arm only when price enters a specific zone.
- Last Price — trigger fires on the last traded price.
- Mark Price — trigger fires on the exchange's mark price (smoother, less wick-sensitive).
TP/SL (Take Profit / Stop Loss)
Global exit levels for the whole grid position. Three modes:
- Price — absolute price levels.
- PNL — exit when total realized + unrealized profit hits a dollar threshold.
- ROI% — exit based on return-on-investment percentage.
Trigger type mirrors Grid Trigger: Last Price vs Mark Price.
Open a position on creation
When checked, the bot immediately opens a position sized to whichever side of the grid the current price sits on. When unchecked, the bot waits passively for price to cross grid lines.
Close all positions on stop
When checked, hitting TP/SL or end of backtest flattens all open positions. When unchecked, positions are left open.
Backtest Settings
These control how QuantConnect runs the generated algorithm.
- Start Date / End Date — the historical window to backtest.
- Resolution — tick granularity.
Minuteis the sweet spot for most grid strategies;Houris faster but misses intrabar fills;Dailyis only useful for sanity checks. - Initial Cash — the starting account balance for the backtest (not the same as Investment — this is the whole account).
Downloading the script
Click Download Script at any time to save the generated LEAN .py file locally. You can then upload it to QuantConnect manually, run it in the LEAN CLI, or inspect the generated strategy code.
The file name follows grid_bot_<SYMBOL>.py.
Deploying to QuantConnect
The Deploy to QuantConnect card pushes the generated algorithm directly into your QC account, creates a project, uploads the code, and compiles it — ready for you to run a backtest with one more click inside QuantConnect.
Step 1 — Connect
Enter your QuantConnect User ID and API Token, then click Connect.
You can find both at: QuantConnect → Account → API Access
On successful connection, the app fetches the list of your existing projects so you can overwrite one if you want.
Note: Your QC credentials are held in-memory on the server only for the duration of your session. They are not written to disk or stored in any database. If the server restarts (including on deploys), you'll need to reconnect.
Step 2 — Choose a deploy mode
- Create new project — creates a fresh QC project with the name you enter.
- Overwrite existing — picks an existing project from the dropdown and replaces its code with the newly generated algorithm.
Step 3 — Deploy
Click Deploy to QuantConnect. The app will:
- Generate the LEAN algorithm from your current config.
- Create or select the target QC project.
- Upload the algorithm as
main.py. - Trigger a compile and report the result.
On success you'll see the compile state plus a clickable link to open the project inside QuantConnect, where you can run a backtest, view logs, and iterate.
If the compile fails, the error message from QC is shown in the result box — fix your config (or report a template bug) and redeploy.
Tips & caveats
- Range is everything. A grid that never sees its range traded is a grid that never earns. Backtest your chosen range over several market regimes.
- Fees matter. Check the Profit/Grid display before deploying. A dense grid with high fees can be net-negative before any market movement.
- Leverage is not free. In futures mode, every increase in leverage pulls your liquidation price toward your range. A grid that gets liquidated is a grid that loses everything.
- The generated algorithm is readable. Download the script and skim it — it's standard LEAN Python and not hiding anything clever. Good place to start if you want to modify the strategy.
- Live trading is opt-in. The "Live Trading (Binance)" card deploys the same algorithm to QuantConnect Cloud against the Binance brokerage. It defaults to testnet (paper) — flip off the testnet checkbox to point at real money. Live deployment requires a paid QC plan with a free live-algorithm node.
- Telegram notifications. Enable the Telegram section under "Advanced" and supply a bot token + chat id. The generated algorithm posts a message on every buy fill, sell fill, trailing shift, and bot stop. Your token is baked into the QC project — anyone with access to that project can read it, so create a dedicated bot rather than reusing a personal one.
Troubleshooting
| Symptom | Likely cause |
|---|---|
| "Authentication failed" on Connect | Wrong User ID, wrong/expired API token, or token lacks API access scope. |
| Deploy succeeds but compile fails | LEAN rejected the generated code. Usually a symbol that's not supported on QC for your chosen resolution, or a date range with no data. |
| "Not connected to QuantConnect" after idling | Server was restarted (likely from a deploy). Reconnect with your credentials. |
Profit/Grid shows --% or negative |
Fill in all required fields; check that Lower Price < Upper Price and fee rate is reasonable. |
| Est. Liq. Price inside the grid | Your leverage is too high for your price range. Reduce leverage or widen the range. |
| "No free live node available" | Your QC plan has no live-algorithm nodes free (either none included or all already running). Upgrade the plan or stop an existing live algorithm. |
| Telegram test button reports "Unauthorized" | Bot token is wrong or revoked. Create a fresh bot via @BotFather and retry. |
| Telegram test succeeds but no messages arrive after deploy | The algorithm can't reach Telegram from QC's network, or the token you pasted into the config differs from the one you tested. Re-paste both fields and redeploy. |
Feedback
This is a self-hosted, source-available tool. Found a bug or want a feature? Open an issue on the GitHub repo.