XAU Grid Bot - Long Strategy by 3Commas

By 3Commas

Performance Metrics

Description

XAU Grid Bot — Long Strategy🔷 What it does:This is a long-only price-grid strategy that operates between two fixed bounds and harvests volatility through repeated round-trips on a pre-defined ladder of price levels. Each level is an independent slot: when price crosses down through a level, the strategy buys one slot; when price crosses up through the level immediately above, that slot is closed for a fixed profit. The grid is generated geometrically by default (constant percent step), so the spacing adapts to the asset's scale. - Up to 48 simultaneous long slots, each sized as a fixed fraction of the total investment. - No trailing exit, no stop loss — the exit for each slot is the level above its entry, full stop. - Risk is structurally capped by bounded total investment (default 20% of equity) — if all 48 slots fill, maximum exposure equals the configured investment and cannot exceed it.🔷 Who is it for: - Swing traders harvesting volatility on range-bound assets where directional bias is unclear. - Traders who want a fully mechanical, no-judgment system that runs around the clock. - Bot operators looking for a chart-driven signal source with per-level webhook JSON ready to drive a DCA Bot configured for grid execution. - Traders running a portfolio of low-correlation strategies who want a low-drawdown contributor.🔷 How does it work: Grid Construction: On script load, the strategy computes N price levels between the configured High and Low bounds. In Geometric mode (default), level k is at High × (Low/High)^(k/(N-1)), giving constant percent spacing. In Arithmetic mode, levels are linearly spaced by absolute price. Per-Slot Logic: Each grid level is an independent slot tracked by a boolean ownership flag. When bar close moves price down through an empty slot's level, a long is opened at that level for one slot's worth of capital (Investment / N). When bar close moves price up through the level immediately above an owned slot, that slot is closed, locking the round-trip profit between the two adjacent levels. No Trailing, No Stop Loss: By design, each slot has a fixed exit (the level above). The strategy never trails the exit and never stops a slot out for a loss — slots that fall below their entry simply wait until price comes back. This is the canonical grid bot behavior. Capital Bounds: Total deployed capital cannot exceed the configured Investment. When all slots are filled, no new orders are opened until price rises and starts closing slots. This structural cap is the strategy's risk control.🔷 Why it's unique: - Per-Level Webhook Ledger: Every fill and close emits a fully-formed JSON alert payload tagged with the specific grid slot ("Grid_BUY_L5" / "Grid_TP_L5"). The strategy can drive a DCA Bot configured for grid emulation without any glue layer. - Pre-Allocated State: All 48 slot ledgers live in fixed-size arrays, so state lookups are constant-time and the chart can render every active slot with no performance overhead even at maximum density. - Honest Backtest Surface: The avg entry line plotted on the chart and the open PnL displayed in the status table both reflect the actual broker-equivalent position state — no shortcut from base entry, no synthetic averaging.🔷 Considerations Before Using the Strategy: Market Selection: Grid strategies are most profitable in range-bound, mean-reverting markets. On strong directional trends, the strategy will keep loading slots as price moves away and won't close any until price reverses. Pick assets that respect a defined range, and re-tune High/Low whenever the regime changes. Range Configuration: The default High/Low (4857.27 / 3568.69) was set against XAUTUSDT historical extremes. Update both bounds before deploying on any other asset — the Geometric spacing is sensitive to the bounds ratio. No Stop Loss Justification: There is no exit on adverse moves below the lowest grid level. The strategy's risk is structurally capped by total Investment — at default settings, the maximum deployed capital across all 48 slots is 2,000 USDT = 20% of equity, and the bounded slot count prevents further drawdown beyond that. If price collapses far below the Low bound, that 20% is held at unrealized loss until recovery. Size the Investment input to match the maximum drawdown you are willing to absorb in a range-break scenario. Trade Volume & Fees: Grid bots generate a high number of round-trips. At default settings, the backtest produced 556 closed trades in 13 months. Realistic commission and slippage are baked into the script; any mismatch with your exchange's actual fees will materially shift the results. Demo Testing: Always demo-test before going live. Past results do not guarantee future performance, especially on a strategy whose profitability is bounded by the chosen High/Low range remaining valid.🔷 STRATEGY PROPERTIES Symbol: BYBIT:XAUTUSDT (Spot) Timeframe: 15M Test Period: Sept 1, 2025 — May 21, 2026 (~13 months) Initial Capital: 10,000 USDT. Order Size per Slot: Investment / Grid Levels (default 2,000 / 48 ≈ 41.67 USDT, ~0.42% of equity per slot). Max Capital Deployed: 2,000 USDT (~20% of equity if all 48 slots fill). Commission: 0.06% per trade. Slippage: 5 ticks. Margin for Long Positions: 100%. Indicator Settings: Default Configuration. Grid Bounds: High 4857.27 / Low 3568.69. Grid Levels: 48 (Geometric spacing). Stop Loss: None — bounded position size is the structural risk cap. Strategy: Long Only.🔷 STRATEGY RESULTS ⚠️ Remember, past results do not guarantee future performance. Net Profit: +101.99 USDT (+1.02%) Max Equity Drawdown: 64.03 USDT (0.64%) Total Closed Trades: 556 Percent Profitable: 67.27% (374 / 556) Profit Factor: 2.267🔷 How to Use It: 🔸 Adjust Settings: Open the strategy inputs and set the High and Low bounds to a range you expect the asset to respect. Pick Geometric for percent-spaced levels (default, recommended for crypto and commodities) or Arithmetic for linearly-spaced levels. Set Grid Levels (5–50) and Total Investment. 🔸 Results Review: Run a full-period backtest and confirm Max Drawdown stays within your personal risk band. Validate that the trade count is high enough to be statistically meaningful (≥ 100 closed trades is a reasonable floor). 🔸 Create alerts to trigger the DCA Bot: Add one alert on the strategy using "Any alert() function call". Paste your DCA Bot's webhook URL into the alert's Webhook field, and fill the Bot ID, Email Token, and Pair inputs on the script. Every grid-level buy and grid-level close will emit a dedicated JSON payload tagged with the slot index, so each level can be tracked independently downstream.🔷 INDICATOR SETTINGS High Price: Top of the grid. The very highest level a slot can be created from. Low Price: Bottom of the grid. The very lowest level a slot can be created from. Grid Levels: Number of price levels between High and Low (default 48, capped at 50). Spacing Mode: Geometric (constant percent step) or Arithmetic (constant absolute step). Total Investment (USDT): Total capital allocated across all slots. Per-slot size = Investment / Grid Levels. Bot ID / Email Token / Pair: Webhook fields injected into every alert payload. Visualization: Toggle grid lines, range box, HIGH/LOW labels, avg entry plot, fill labels, status table. Brand Watermark: Configurable text, position, size, and transparency.👨🏻‍💻💭 We hope this tool helps enhance your trading. Your feedback is invaluable, so feel free to share any suggestions for improvements or new features you'd like to see implemented.__The information and publications within the 3Commas TradingView account are not meant to be and do not constitute financial, investment, trading, or other types of advice or recommendations supplied or endorsed by 3Commas and any of the parties acting on behalf of 3Commas, including its employees, contractors, ambassadors, etc.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView