# Manual Entry, Automatic Exit: Using XQ Semi-Automated Trading to Free Up Office Workers

- Channel: 量化交易科學園區 - 江加宏
- Published: 2023-04-28
- Series: [Quant Trading Science Park](https://xknow.app/en/s/quant-trading-science-park/?ref=agent) ([series index](https://xknow.app/en/s/quant-trading-science-park/llms.txt))
- Topics: [Technical Analysis](https://xknow.app/en/topics/technicals/llms.txt), [AI & Software Engineering](https://xknow.app/en/topics/ai-engineering/llms.txt)
- Page: https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent
- YouTube: https://www.youtube.com/watch?v=zCIoxQi9J08

> Pick more precise entry points by hand and let an XQ script exit automatically under preset conditions, so office workers don't have to watch the market and can focus on improving entry quality.

## Key ideas

- XQ's full automated trading covers stock selection, entry and exit, but some people feel its entry points can only be described in a fairly generic way and are not precise enough, so they enter manually and leave the exit to XQ.
- For the script to detect manually placed orders, the key is to specify the inventory and the monitored account in the automated trading settings and check "automatically add to execution when inventory changes"; the execution frequency depends on the trading cycle, for example 1 minute for day trading.
- The exit conditions are written entirely in the script: the simplest is that while holding a position, it exits when the closing price exceeds the average entry price by a set percentage; the advanced version can add take-profit, stop-loss, moving average crossover, point change, holding time, and the stock version can also set a final exit time to avoid holding positions overnight.
- In a live test with a simulated long order, once it filled the script found the position and exited automatically when the condition of crossing below the moving average was met, confirming that manual entry combined with automatic exit works.
- Handing the exit to the script saves the effort of watching both entry and exit at once, and removes the worry of a short squeeze or a long position hitting limit-down, so entry quality can improve.

## Section summaries

### 0:05 The Idea of Manual Entry with XQ Automatic Exit

XQ automated trading covers stock selection, entry and exit, but some people think its entry points are not precise enough. The speaker proposes entering manually and letting XQ exit automatically, and first demonstrates adding an automatic exit script to the trading functions.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent#s-0) | [YouTube 0:05](https://www.youtube.com/watch?v=zCIoxQi9J08&t=5s)

### 2:05 Writing the Simplest Percentage Exit Script

This demonstrates the most basic exit logic: when the position is not 0, exit if the closing price is above the average entry price by the set percentage. Once the code is compiled, the script is added to automated trading and selected.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent#s-1) | [YouTube 2:05](https://www.youtube.com/watch?v=zCIoxQi9J08&t=125s)

### 3:05 Automated Trading Settings and Inventory-Change Triggering

In the settings you must specify the inventory and the monitored account, and the execution frequency depends on the trading cycle; a day trading program can use 1 minute. The key is to check automatically adding to execution when inventory changes, so the script can detect manually placed orders and exit on your behalf.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent#s-2) | [YouTube 3:05](https://www.youtube.com/watch?v=zCIoxQi9J08&t=185s)

### 4:35 Order Types and Conditions in the Futures Exit-Assist Script

The self-made futures exit-assist script lets you choose the order type: for limit orders, the price is tied to the trigger price, with buys at 2 ticks higher and sells at 2 ticks lower; futures use range market orders, while stocks simply use market orders. You can also set exit conditions such as take-profit, stop-loss, candlestick size, moving average crossover, point change and holding time.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent#s-3) | [YouTube 4:35](https://www.youtube.com/watch?v=zCIoxQi9J08&t=275s)

### 7:35 Simulated Long Order Test and the Stock Version Script

After a simulated long order filled, the script detected the position and exited automatically when price broke below the moving average, confirming it works. The stock version can also set take-profit, stop-loss, holding time and a final exit before the close, letting traders focus on improving entry quality.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent#s-4) | [YouTube 7:35](https://www.youtube.com/watch?v=zCIoxQi9J08&t=455s)

---

Full notes (with slides) and other episodes in this series: https://xknow.app/en/v/quant-trading-science-park-ep14/?ref=agent

Watch the original video: https://www.youtube.com/watch?v=zCIoxQi9J08
