← Back to app

Grid Trading Bot

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

  1. Pick Futures or Spot mode at the top.
  2. Fill in Symbol, Lower Price, Upper Price, Number of Grids, and Investment.
  3. Watch the Profit/Grid, Qty/Order, and (for futures) Est. Liq. Price update as you type — these are computed live.
  4. Set your Backtest Settings (start/end date, resolution, initial cash).
  5. Click Download Script to grab the generated LEAN .py file, 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

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

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)

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.

TP/SL (Take Profit / Stop Loss)

Global exit levels for the whole grid position. Three modes:

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.


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

Step 3 — Deploy

Click Deploy to QuantConnect. The app will:

  1. Generate the LEAN algorithm from your current config.
  2. Create or select the target QC project.
  3. Upload the algorithm as main.py.
  4. 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


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.