# Auto Trader

### Overview

**Auto Trader** is a premium cloud-based execution platform that enables users to fully automate their TradingView strategies across supported brokers and proprietary trading firms. It seamlessly links TradingView strategy alerts directly to your brokerage accounts, automatically placing and managing trades based on received signals.

Engineered for professional performance, the Auto Trader utilizes websocket routes to achieve industry-leading execution latencies of 5 to 10 milliseconds. Because the entire system is hosted in the cloud, it operates 24/7 without requiring a Virtual Private Server (VPS), desktop software, or continuous manual monitoring. It handles intelligent order routing, advanced risk management, and multi-account trade replication instantly.

### How It Works

The automation pipeline is designed to be simple, secure, and lightning-fast:

1. **Select a Strategy:** Utilize any TradingView strategy that generates buy or sell signals.
2. **Configure Automation:** Create an automation profile within the Lune dashboard by selecting your target accounts and defining your execution settings.
3. **Generate Credentials:** Lune automatically generates a unique, secure Webhook URL and an alert message template specifically for your automation.
4. **Set the Alert:** In TradingView, create a new alert for your strategy, pasting the Lune Webhook URL and the message template.
5. **Live Execution:** When the strategy triggers a signal, TradingView fires the alert to Lune. The platform instantly validates the signal against your Risk Management rules and executes the order across your connected broker accounts.

### Creating an Automation

Setting up a new automation involves a streamlined configuration process to ensure your strategy executes exactly as intended.

#### Step 1: Select Target Accounts

Choose one or multiple connected broker accounts to receive the automated trades.

* **Size Multiplier:** Set a per-account multiplier (minimum 0.1) to scale the position size up or down based on the specific account balance.
* **Instrument Routing**:&#x20;
  * **Auto Root (Default):** Automatically routes to the root symbol (e.g., ES, NQ).
  * **Specific Contract:** Routes to an exact, user-defined broker contract (e.g., ESZ24).

#### Step 2: Enter Strategy Name

Input the exact name of your strategy. This text field must perfectly match the strategy name defined in your TradingView alert to ensure signals are routed correctly.

#### Step 3: Select Quantity Mode

Choose how the Auto Trader determines the number of contracts to buy or sell.

| Quantity Mode                | Description                                                                                                                                                                          |
| ---------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **Static Position Size**     | You define a fixed number of contracts per trade. Per-account multipliers are applied to this static number. Partial exits are enabled by default.                                   |
| **Strategy Quantity (Raw)**  | Executes the exact quantity sent by the TradingView strategy payload. Per-account multipliers are applied. Partial exits are automatically disabled to mirror the strategy strictly. |
| **Scaled Strategy Quantity** | Available for strategies linked from the Strategy Explorer. Scales the strategy's baseline order size to your desired position size, adjusting dynamically.                          |

#### Step 4: Configure Execution Settings

Fine-tune how the system handles order entry and exit attempts.

| Setting                  | Default        | Description                                                                                                               |
| ------------------------ | -------------- | ------------------------------------------------------------------------------------------------------------------------- |
| **Max Entry Signal Age** | 30,000ms (30s) | Rejects stale entry signals that arrive older than this threshold.                                                        |
| **Entry Max Retries**    | 3              | The maximum number of retry attempts for failed entry orders.                                                             |
| **Entry Retry Delay**    | 2,000ms        | The delay duration between entry retry attempts.                                                                          |
| **Exit Max Retries**     | 5              | The maximum number of retry attempts for failed exit orders.                                                              |
| **Respect Account Risk** | On             | Enforces all account risk limits (daily loss, max position, blackouts). If disabled, the automation bypasses risk checks. |

#### Step 5: Configure Partial Exits (Optional)

If utilizing a Static Position Size, you can enable partial exits. You define a partial exit percentage (between 10% and 90%, defaulting to 50%). If your position size is only 1 contract, a partial exit signal will automatically round to a full 1-contract exit.

#### Step 6: Max Position Size Cap (Optional)

Enable this to set a hard maximum limit on the number of contracts allowed per position for this specific automation, acting as an extra layer of safety.

### Alert Setup

Once your automation is saved, the platform provides the necessary webhook data to connect TradingView.

Important: Your Webhook URL is private and acts as a secure credential. Do not share it, as anyone with the URL can send trade signals to your accounts.

#### TradingView Single Alert Configuration

This standard setup works with any TradingView strategy using a single dynamic alert message.

**Standard JSON Template:**

```json
{
  "strategy_id": "your_strategy_id",
  "strategy_name": "YourStrategyName",
  "strategy_order_action": "{{strategy.order.action}}",
  "strategy_prev_market_position": "{{strategy.prev_market_position}}",
  "strategy_market_position": "{{strategy.market_position}}",
  "quantity": "{{strategy.order.contracts}}",
  "bar_close_price": "{{close}}",
  "order_fill_price": "{{strategy.order.price}}"
}
```

*Note: The `quantity` field is only required and included when the quantity mode is set to Strategy or Scaled Strategy.*

**Setup Steps:**

1. Open your TradingView chart and apply your desired strategy.
2. Click to create a new alert based on the strategy.
3. Check the "Webhook URL" box and paste your unique Lune Webhook URL.
4. Paste the JSON alert message template into the "Message" box.
5. Save the alert.

### Execution Monitor

The Execution Monitor provides a real-time dashboard to track the status of every automated signal processed by the system.

* **Stats Cards:** Displays Total Executions, Successful Executions, Failed Executions, Pending Orders, and Average Latency.
* **Execution Table:** A detailed log showing the relative time, strategy/account name, action taken (e.g., LongEntry, ShortExit), symbol, quantity, and status.
* **Latency Tracking:** Execution speeds are color-coded for quick diagnostics (Green for under 200ms, Yellow for 200 to 500ms, and Red for over 500ms).

### Global Automation Settings

Accessible via the settings gear icon, these configurations apply default behaviors across all your automations.

* **Exit Order Protection:** Includes toggles to Enable Exit Recovery, Verify Position Before Retry, and Flatten on Max Retries. This ensures the system aggressively attempts to close positions during volatile conditions.
* **Notifications:** Toggle alerts for general execution failures or critical system failures.

### Best Practices & Important Notes

* **Updating Alerts:** A new alert MUST be created in TradingView anytime you change your strategy settings on the chart. Existing TradingView alerts do not update their internal parameters automatically.
* **Rate Limits:** The system enforces a generous rate limit of 50 signals per second, per user.
* **Exit Priority:** Exit signals are prioritized and are always processed, regardless of signal age or standard risk management blocks, ensuring you can always close open exposure.
* **Journal Integration:** Every automated execution is automatically logged in the Trading Journal with the specific automation tagged as the source.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.lunefi.com/lune-platform/auto-trader.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
