OPEN-SOURCE SCRIPT
[3Commas] BTC Grid - Long Indicator

[3Commas] BTC Grid — Long Indicator
🔷 What it does:
This is a signal-only indicator that mirrors a price-grid long workflow on BTCUSDT.P between two fixed bounds. It tracks up to 50 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, open PnL, and realized PnL from the live slot ledger and renders all of it on the chart.
* Pre-computes 7–200 grid levels in Geometric 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 BTC 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, 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 virtual broker-equivalent position state. The table also accumulates realized PnL from every closed slot.
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.
🔷 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.
* Fill-by-Fill Avg Entry: The orange avg-entry line is derived from running totals updated on every event.
* Active Slot Highlighting: Owned grid levels are rendered with a thicker green stroke; empty slots stay dashed gray.
* Range Box & Bounds Labels: A semi-transparent box spans the configured High/Low range, with HIGH/LOW labels marking the bounds.
* Calibrated for BTCUSDT.P 15m: Default bounds, level count, and step size are set for BTC’s broad range, with a geometric ladder designed around ~1% spacing.
🔷 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 will not free until price reverses.
Capital Deployment: The default Total Investment of 10,000 USDT is a virtual reference used for avg-entry and open-PnL computation. Real sizing happens on the bot side.
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.
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, the indicator state may not match the live bot.
No Stop Loss: There is no exit signal on adverse moves below the lowest grid level. Risk should be managed on the bot side through capital allocation, range selection, or additional stop logic.
Backtesting Note: This is an indicator, not a strategy. There is no built-in P&L tester. For performance metrics, use the companion strategy version on identical parameters.
🔷 How to Use It:
🔸 Add the indicator to a BTCUSDT.P 15m chart.
🔸 Set the High and Low bounds to a BTC range you expect the market to respect.
🔸 Pick Geometric spacing for percent-based levels or Arithmetic spacing for absolute-price levels.
🔸 Set Grid Levels and the virtual Total Investment used for avg-entry computation.
🔸 In the DCA Bot Webhook group, paste your Bot ID, Email Token, and Pair in QUOTE_BASE format, for example USDT_BTC.
🔸 Create an alert on the indicator with “Any alert() function call”. Paste the DCA Bot’s webhook URL into the alert’s Webhook field.
🔷 INDICATOR SETTINGS
High Price: Top of the grid.
Low Price: Bottom of the grid.
Grid Levels: Number of price levels between High and Low.
Spacing Mode: Geometric or Arithmetic.
Total Investment: Virtual capital allocated across all slots.
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, and watermark.
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.
🔷 What it does:
This is a signal-only indicator that mirrors a price-grid long workflow on BTCUSDT.P between two fixed bounds. It tracks up to 50 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, open PnL, and realized PnL from the live slot ledger and renders all of it on the chart.
* Pre-computes 7–200 grid levels in Geometric 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 BTC 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, 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 virtual broker-equivalent position state. The table also accumulates realized PnL from every closed slot.
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.
🔷 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.
* Fill-by-Fill Avg Entry: The orange avg-entry line is derived from running totals updated on every event.
* Active Slot Highlighting: Owned grid levels are rendered with a thicker green stroke; empty slots stay dashed gray.
* Range Box & Bounds Labels: A semi-transparent box spans the configured High/Low range, with HIGH/LOW labels marking the bounds.
* Calibrated for BTCUSDT.P 15m: Default bounds, level count, and step size are set for BTC’s broad range, with a geometric ladder designed around ~1% spacing.
🔷 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 will not free until price reverses.
Capital Deployment: The default Total Investment of 10,000 USDT is a virtual reference used for avg-entry and open-PnL computation. Real sizing happens on the bot side.
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.
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, the indicator state may not match the live bot.
No Stop Loss: There is no exit signal on adverse moves below the lowest grid level. Risk should be managed on the bot side through capital allocation, range selection, or additional stop logic.
Backtesting Note: This is an indicator, not a strategy. There is no built-in P&L tester. For performance metrics, use the companion strategy version on identical parameters.
🔷 How to Use It:
🔸 Add the indicator to a BTCUSDT.P 15m chart.
🔸 Set the High and Low bounds to a BTC range you expect the market to respect.
🔸 Pick Geometric spacing for percent-based levels or Arithmetic spacing for absolute-price levels.
🔸 Set Grid Levels and the virtual Total Investment used for avg-entry computation.
🔸 In the DCA Bot Webhook group, paste your Bot ID, Email Token, and Pair in QUOTE_BASE format, for example USDT_BTC.
🔸 Create an alert on the indicator with “Any alert() function call”. Paste the DCA Bot’s webhook URL into the alert’s Webhook field.
🔷 INDICATOR SETTINGS
High Price: Top of the grid.
Low Price: Bottom of the grid.
Grid Levels: Number of price levels between High and Low.
Spacing Mode: Geometric or Arithmetic.
Total Investment: Virtual capital allocated across all slots.
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, and watermark.
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.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
📈 Stop guessing your settings — backtest & optimize with QuantPilot
🎁 Free to start
🎁 Free to start
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
📈 Stop guessing your settings — backtest & optimize with QuantPilot
🎁 Free to start
🎁 Free to start
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน