OPEN-SOURCE SCRIPT

BNB Grid - Long Indicator

287
BNB Grid — Long Indicator

🔷 What it does:
This is a signal-only indicator that mirrors a price-grid long workflow on BNB / USDT between two fixed bounds. It tracks up to 17 independent virtual slots between a configurable High and Low — each slot fires a webhook-ready buy signal when price crosses down through it, and a paired sell signal when price subsequently crosses up through the slot immediately above. The indicator computes a running average entry, total deployed capital, and open PnL from the live slot ledger and renders all of it on the chart.
- Pre-computes 7–200 grid levels in Geometric (default) or Arithmetic spacing.
- Each slot is an independent ownership flag with its own buy/sell webhook payload.
- Avg entry is derived from fill-by-fill bookkeeping — total cost and total qty are updated on every event.
- Every event emits a webhook-ready JSON alert payload tagged with the specific grid slot.

🔷 Who is it for:
- Swing traders harvesting volatility on BNB in range-bound regimes.
- Bot operators looking for a chart-driven signal source that emits per-slot JSON ready for a DCA Bot configured for grid execution.
- Traders who want to monitor a virtual grid state — avg entry, owned slots, deployed capital, open PnL — directly on the chart without a backtest engine.
- Portfolio operators using a high-trade-count contributor alongside directional strategies.

🔷 How does it work:
Grid Construction: On script load, the indicator 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 — approximately 1.0% per step at default settings. In Arithmetic mode, levels are linearly spaced by absolute price.
Per-Slot State Machine: Each grid level is an independent slot tracked by a boolean ownership flag. When close price crosses down through an empty slot's level, the slot is marked owned, virtual cost-basis is added, and the BUY webhook payload is dispatched. When close price crosses up through the level immediately above an owned slot, the slot is marked free, virtual cost-basis is subtracted, and the SELL webhook payload is dispatched.
Honest Virtual Bookkeeping: Total cost and total qty are updated incrementally on each event, so the avg entry, deployed capital, and open PnL displayed in the status table reflect the actual broker-equivalent position state — no shortcuts from base entry, no synthetic averaging. The table also accumulates the realized PnL from every closed slot (the exact round-trip profit between adjacent levels), so it shows how much the grid has actually earned over the chart history.
No Trailing, No Stop Loss: By design, each slot has a fixed exit (the level above). The indicator never trails the exit and never signals a slot-out for a loss — slots that fall below their entry stay owned until price comes back. This is the canonical grid-bot behavior.

🔷 Why it's unique:
- Per-Level Webhook Ledger: Every BUY and SELL emits a fully-formed JSON alert payload tagged with the specific grid slot ("Grid_BUY_L5" / "Grid_TP_L5"). The indicator can drive a DCA Bot configured for grid emulation without any glue layer.
- Fill-by-Fill Avg Entry: The orange avg-entry line is derived from running totals updated on every event — what you see is what the broker-equivalent position would actually have.
- Active Slot Highlighting: Owned grid levels are rendered with a thicker green stroke; empty slots stay dashed gray. Slot density and current loading are visible at a glance.
- Range Box & Bounds Labels: A semi-transparent box spans the configured High/Low range, and crisp HIGH/LOW labels mark the bounds — the grid topology is obvious without zooming.
- Calibrated for BNB 15m: Default bounds, level count, and step size are set against BNB's recent observed range. The 17-level geometric ladder gives roughly 1.0% per step — wide enough to clear perpetual taker fees on each round-trip, granular enough to keep catching 15m swings inside the range.

🔷 Considerations Before Using the Indicator:
Market Selection & Range Validity: Grid strategies are most profitable in range-bound, mean-reverting markets. On strong directional trends below the configured Low, slots will keep marking as owned as price falls and won't free until price reverses. The default High/Low (667 / 569) was set against BNB's recent observed range; update both whenever the regime changes.
Capital Deployment: The default Total Investment of 10,000 USDT is a virtual reference used for the avg-entry and open-PnL computation. The real sizing happens on the bot side — match the indicator's per-slot allocation to your bot's grid configuration to keep the avg-entry display honest.
Cross Detection Granularity: Crossings are detected on bar close, comparing the current close to the previous close. A bar that spikes through a level and returns within the same bar may be missed by design — this prevents over-signaling on intra-bar wicks.
Live vs Historical State: The virtual slot ledger is rebuilt from chart history each time the indicator is recompiled. If the indicator is added mid-deployment or the live bot diverges from the signal stream (manual interventions, partial fills), the indicator state may not match the live bot. Toggle the indicator off and on to reset.
No Stop Loss: There is no exit signal on adverse moves below the lowest grid level. Risk is structurally capped on the bot side by the bounded Total Investment configured at the bot. If a hard stop is required, layer it on the bot side.
Backtesting Note: This is an indicator, not a strategy. There is no built-in P&L tester. For performance metrics over a ~3.8-month sample (330 closed trades, 72.42% win rate, 5.44% max drawdown, profit factor 3.061, +13.16% net return), use the companion strategy version on identical parameters.

🔷 How to Use It:
🔸 Add the indicator to a BNB / USDT 15m chart.
🔸 Set the High and Low bounds to a range you expect BNB to respect.
🔸 Pick Geometric (default, recommended) or Arithmetic spacing.
🔸 Set Grid Levels (7–200) and the virtual Total Investment used for avg-entry computation.
🔸 In the DCA Bot Webhook group, paste your Bot ID, Email Token, and Pair (QUOTE_BASE format, e.g., USDT_BNB).
🔸 Create an alert on the indicator with "Any alert() function call". Paste the DCA Bot's webhook URL into the alert's Webhook field. 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 highest level a slot can be created from.
Low Price: Bottom of the grid. The lowest level a slot can be created from.
Grid Levels: Number of price levels between High and Low (default 17, range 7–200).
Spacing Mode: Geometric (constant percent step) or Arithmetic (constant absolute step).
Total Investment (USDT): Virtual capital allocated across all slots. Used for the avg-entry and open-PnL computation only.
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, signal triangles, status table (shows status, range, levels, owned slots, avg entry, deployed capital, open PnL, and cumulative realized PnL).
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.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.