# 🔄 Automating Infinity Algo Alerts via WunderTrading

Connect Infinity Algo signals to WunderTrading for automated trading with flexible position management.

***

### 🎯 Two Trading Workflows

{% tabs %}
{% tab title="🔄 Swing Trade" %}
**Auto-Flip Positions (Futures Only)**

**What it does:**

* Automatic Long ↔ Short flipping
* Just two alerts needed
* Bot handles position reversal
* With Swing Trade ON, Enter-Long/Enter-Short flip positions automatically

**Best for:**

* ✅ Futures trading only
* ✅ Trending markets
* ✅ Minimal alerts
* ✅ Always in position

{% code title="Setup Requirements" %}

```
Swing Trade: ON (Futures only!)
Alerts: 2 total
- Buy Signal → Enter-Long
- Sell Signal → Enter-Short
(Exit-All only for flattening without opening opposite)
```

{% endcode %}

{% hint style="warning" %}
**Important:** Swing trade functionality is only available for Futures markets.
{% endhint %}
{% endtab %}

{% tab title="🎯 Explicit Exit" %}
**Manual Position Control**

**What it does:**

* Full control over exits
* No position overlap
* Works on Spot & Futures
* Clear entry/exit separation

**Best for:**

* ✅ Spot trading
* ✅ Risk management
* ✅ Position gaps
* ✅ More control

{% code title="Setup Requirements" %}

```
Swing Trade: OFF
Alerts: 3+ total
- Entry → Enter-Long/Enter-Short
- Exit → Exit-Long/Exit-Short
- Optional re-entry
```

{% endcode %}

{% hint style="info" %}
Perfect for traders who want complete control over position timing
{% endhint %}
{% endtab %}
{% endtabs %}

***

### ⚙️ Step 1: Build Signal Bot in WunderTrading

**Navigate to WunderTrading:**

1. **Log in** → **Bots** → **Signal Bot** → **Create bot**
2. Configure **General tab** settings:

| Field                | Value                       |
| -------------------- | --------------------------- |
| **Name**             | e.g. `Infinity Algo BTC`    |
| **Exchange/API**     | Select your exchange API    |
| **Pairs**            | Select up to 10 pairs in UI |
| **Timeframe label**  | Any (just a label)          |
| **Multiple entries** | ON for scale-ins            |
| **Swing trade**      | ON for auto-flip (Futures)  |

{% hint style="danger" %}
**Note:** Pairs must be selected in the bot UI. JSON cannot override pair selection.
{% endhint %}

***

### 📩 Step 2: Configure Entries & Get Webhook

**Entries tab configuration:**

| Setting                 | Value               |
| ----------------------- | ------------------- |
| **Bot start condition** | *TradingView Alert* |
| **Bot settings format** | **JSON**            |

After saving, your bot will display:

* **Webhook URL:** Copy the exact URL shown in your bot's Alerts tab
* **Alert comments:** Copy exactly as shown (default: `Enter-Long`, `Enter-Short`, `Exit-All`)

{% hint style="warning" %}
**Critical:**

* Copy the exact webhook URL from your bot - don't guess the format
* Comment codes are case-sensitive and may change if you edit bot Name/Exchange/Timeframe/Pair
* After any bot edits, update your TradingView alerts to match
  {% endhint %}

***

### 📊 Step 3: Create TradingView Alerts

**Standard Alert Settings**

| Field           | Value                                                         |
| --------------- | ------------------------------------------------------------- |
| **Condition**   | Select your Infinity Algo signal (e.g., "Buy Signal - Smart") |
| **Options**     | **Once Per Bar Close** (prevents duplicate orders)            |
| **Webhook URL** | Paste the exact URL from your bot's Alerts tab                |
| **Message**     | JSON template (see below)                                     |

***

### 📝 JSON Templates

{% hint style="info" %}
**Important:** Use the exact comment codes shown in your bot's sidebar (e.g., `Enter-Long`, not `ENTER-LONG`)
{% endhint %}

{% tabs %}
{% tab title="🟢 Long Entry" %}
{% code title="enter\_long.json" overflow="wrap" lineNumbers="true" %}

```json
{
  "code": "Enter-Long",            // must match your bot's comment EXACTLY
  "orderType": "market",
  "amountPerTradeType": "quote",   // quote currency (e.g., USDT on BTC/USDT)
  "amountPerTrade": 150,
  
  "takeProfits": [
    { "priceDeviation": 0.01, "portfolio": 0.25 },
    { "priceDeviation": 0.02, "portfolio": 0.25 },
    { "priceDeviation": 0.03, "portfolio": 0.25 },
    { "priceDeviation": 0.04, "portfolio": 0.15 },
    { "priceDeviation": 0.05, "portfolio": 0.07 },
    { "priceDeviation": 0.06, "portfolio": 0.03 }
  ],
  
  "stopLoss": { "priceDeviation": 0.01 },
  "reduceOnly": true,              // prevents exits from increasing size (Futures only)
  "placeConditionalOrdersOnExchange": false
}
```

{% endcode %}

{% hint style="success" %}
**Note:** TP portfolios must sum to exactly 1.0 (100%)
{% endhint %}
{% endtab %}

{% tab title="🔴 Short Entry" %}
{% code title="enter\_short.json" overflow="wrap" lineNumbers="true" %}

```json
{
  "code": "Enter-Short",           // change only this line
  "orderType": "market",
  "amountPerTradeType": "quote",   // quote currency
  "amountPerTrade": 150,
  
  "takeProfits": [
    { "priceDeviation": 0.01, "portfolio": 0.25 },
    { "priceDeviation": 0.02, "portfolio": 0.25 },
    { "priceDeviation": 0.03, "portfolio": 0.25 },
    { "priceDeviation": 0.04, "portfolio": 0.15 },
    { "priceDeviation": 0.05, "portfolio": 0.07 },
    { "priceDeviation": 0.06, "portfolio": 0.03 }
  ],
  
  "stopLoss": { "priceDeviation": 0.01 },
  "reduceOnly": true
}
```

{% endcode %}
{% endtab %}

{% tab title="✅ Exit Long" %}
{% code title="exit\_long.json" overflow="wrap" %}

```json
{
  "code": "Exit-Long",
  "orderType": "market",
  "reduceOnly": true
}
```

{% endcode %}

Skip if using Swing trade ON
{% endtab %}

{% tab title="❌ Exit Short" %}
{% code title="exit\_short.json" overflow="wrap" %}

```json
{
  "code": "Exit-Short",
  "orderType": "market",
  "reduceOnly": true
}
```

{% endcode %}

Skip if using Swing trade ON
{% endtab %}

{% tab title="⏹️ Exit All" %}
{% code title="exit\_all.json" overflow="wrap" %}

```json
{
  "code": "Exit-All",
  "orderType": "market",
  "reduceOnly": true
}
```

{% endcode %}

Closes all positions at market
{% endtab %}
{% endtabs %}

***

### ⚡ Quick Comparison

| Feature              | Swing Trade ON  | Explicit Exit            |
| -------------------- | --------------- | ------------------------ |
| **Market Type**      | ⚠️ Futures only | ✅ Spot & Futures         |
| **Alerts Needed**    | 2 (minimal)     | 3+ (entry/exit/re-entry) |
| **Position Control** | Automatic flip  | Manual control           |
| **Position Gaps**    | Never           | Possible                 |
| **Complexity**       | Simple          | Moderate                 |

***

### 🎯 Pick Your Workflow

| If you want…                                                                                          | Use these alerts & JSON                                                                                                                                                                                                                                                                            |
| ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>A) Ping-pong (auto flip)</strong><br><em>Long → Short → Long with just two alerts</em></p> | <p><em>Turn <strong>Swing trade = ON</strong> in bot (Futures only)</em><br>• <strong>Buy alert</strong> → <code>Enter-Long</code> JSON<br>• <strong>Sell alert</strong> → <code>Enter-Short</code> JSON<br>• Use <code>Exit-All</code> only when you want to flatten without opening opposite</p> |
| <p><strong>B) Explicit exit first</strong><br><em>Never overlap positions; more control</em></p>      | <p><em>Leave Swing trade = OFF</em><br>• <strong>Entry alert</strong> → <code>Enter-Long</code> or <code>Enter-Short</code> JSON<br>• <strong>Exit alert</strong> → <code>Exit-Long</code> or <code>Exit-Short</code> JSON<br>• <em>(Optional)</em> second entry alert to reverse</p>              |

***

### 🚀 Advanced Features

{% tabs %}
{% tab title="📈 Multiple TPs" %}
**0-6 Take Profit Levels**

* Add up to **6 TP steps**
* Portfolios must sum to **1.0**
* Multi-pair requires `priceDeviation` (decimals, not %)
* Single-pair can use `price`

{% code title="Example: 6-Level TP" %}

```json
"takeProfits": [
  { "priceDeviation": 0.01, "portfolio": 0.30 },
  { "priceDeviation": 0.02, "portfolio": 0.25 },
  { "priceDeviation": 0.03, "portfolio": 0.20 },
  { "priceDeviation": 0.04, "portfolio": 0.15 },
  { "priceDeviation": 0.05, "portfolio": 0.07 },
  { "priceDeviation": 0.06, "portfolio": 0.03 }
]
```

{% endcode %}

Sum = 1.0 (100%) ✅
{% endtab %}

{% tab title="🔄 Scale-In" %}
**Multiple Entries**

Enable in bot settings for:

* DCA on consecutive signals
* Building larger positions
* Averaging entry price

Works with both workflows
{% endtab %}

{% tab title="🛡️ Position Sizing" %}
**amountPerTradeType options:**

**Spot markets:**

* `quote` - Quote currency (e.g., USDT)
* `base` - Base currency (e.g., BTC)
* `percents` - Percentage of balance

**Derivatives/Futures:**

* `quote` - Quote currency
* `contracts` - Number of contracts
* `percents` - Percentage of balance
  {% endtab %}
  {% endtabs %}

***

### 🧠 Pro Tips

{% hint style="info" %}
**Multi-pair bots:** Use `priceDeviation` (decimals like 0.02 for 2%), not `price` for TP/SL
{% endhint %}

* **priceDeviation format** – Use decimals (0.02) not percentages (2%)
* **Portfolio sum** – TP portfolios must add up to exactly 1.0 (100%)
* **reduceOnly** – Applies to exits; has no effect on Spot markets
* **Comment codes** – Copy exactly from your bot; they change if you edit bot settings
* **Strategy alerts** – Use `alert()` function with `{{strategy.order.comment}}` for strategies
* **Paper test first** – WunderTrading log shows "Signal executed" if webhook parsed correctly

***

### 🛠️ Troubleshooting Checklist

| Symptom                         | Likely cause / fix                                                            |
| ------------------------------- | ----------------------------------------------------------------------------- |
| **No deal appears**             | `code` in JSON doesn't match bot's Alert comment exactly (check case!)        |
| **Bot opens but doesn't close** | Swing trade OFF and you forgot exit alert – or `reduceOnly:false` caused flip |
| **Webhook error 400**           | JSON syntax error or using `%` instead of decimals (use `0.02`, not `2%`)     |
| **Duplicate deals**             | Alert set to "Once Per Bar" instead of "Once Per Bar Close"                   |
| **Multi-pair TP/SL fails**      | Must use `priceDeviation` (decimals), not `price`                             |
| **Comments changed**            | Bot edits can change comment codes - update alerts after any bot changes      |

***

### 🔤 JSON Key Reference

| Key                                    | What it does             | Details                                                                                                                                             |
| -------------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`code`**                             | Alert comment identifier | Must match bot's comment exactly (case-sensitive!)                                                                                                  |
| **`orderType`**                        | Order execution type     | `market` or `limit`                                                                                                                                 |
| **`amountPerTradeType`**               | Position size unit       | <p>Spot: <code>quote</code>/<code>base</code>/<code>percents</code><br>Futures: <code>quote</code>/<code>contracts</code>/<code>percents</code></p> |
| **`amountPerTrade`**                   | Position size            | Value depends on type above                                                                                                                         |
| **`takeProfits`**                      | Array of partial exits   | <p><code>priceDeviation</code>: decimal (0.02 = 2%)<br><code>portfolio</code>: fraction to close (must sum to 1.0)</p>                              |
| **`stopLoss`**                         | Stop loss configuration  | `priceDeviation`: decimal from entry                                                                                                                |
| **`reduceOnly`**                       | Prevent size increase    | `true` → exits only decrease position (Futures only, no effect on Spot)                                                                             |
| **`placeConditionalOrdersOnExchange`** | Where orders execute     | <p><code>false</code> = managed by bot<br><code>true</code> = on exchange</p>                                                                       |

***

### 🎯 Which Workflow Should You Use?

{% columns %}
{% column width="50%" %}
**Choose Swing Trade if:**

* Trading Futures only
* Want minimal alerts
* Trust your signals
* Always in position
  {% endcolumn %}

{% column %}
**Choose Explicit Exit if:**

* Trading Spot markets
* Need position control
* Want gap periods
* Risk management focus
  {% endcolumn %}
  {% endcolumns %}

{% hint style="success" %}
**Pro Tip:** Start with Explicit Exit to learn, then switch to Swing Trade for Futures efficiency
{% endhint %}

***

### 📚 Resources

{% hint style="info" %}
**Official WunderTrading Documentation:**

* **Main Docs:** [**https://help.wundertrading.com/en/**](https://help.wundertrading.com/en/)
* **Signal Bot Form Guide:** <https://help.wundertrading.com/en/articles/10458409-signal-bot-comprehensive-form-guide>
* **JSON Guide:** <https://help.wundertrading.com/en/articles/10475473-signal-bot-comprehensive-json-guide>
* **TradingView Setup:** <https://help.wundertrading.com/en/articles/5173846-how-to-set-up-a-tradingview-bot-signal-bot-in-wundertrading>
* **Troubleshooting:** <https://help.wundertrading.com/en/articles/5173235-my-signal-bot-does-not-work>
  {% endhint %}

{% hint style="warning" %}
**Important Reminders:**

* WunderTrading is a third-party service with separate subscription costs
* Always test with small amounts or paper trading first
* Comment codes are case-sensitive and can change when you edit bot settings
* Manual trading via TradingView is always available as an alternative
  {% endhint %}


---

# Agent Instructions: 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.infinityalgo.com/trading-guide/trading-guide/automating-infinity-algo-alerts-via-wundertrading.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.
