# Automated Trading Without Coding Skills: Split a Strategy into Four Building Blocks of Stock Selection, Entry, Exit and Position Control

- Channel: 量化交易科學園區 - 江加宏
- Published: 2023-05-14
- 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: [AI & Software Engineering](https://xknow.app/en/topics/ai-engineering/llms.txt)
- Page: https://xknow.app/en/v/quant-trading-science-park-ep15/?ref=agent
- YouTube: https://www.youtube.com/watch?v=GvsBj7zTOrQ

> You can do automated trading even if you are not good at coding by splitting a strategy into four blocks (stock selection, entry, exit and position control); each block is small and easy to understand, so they can be handled separately and recombined repeatedly.

## Key ideas

- Splitting a single trading program into four parts (stock selection, exit logic, entry logic and position control) makes each piece small and easy to understand, so the amount of code you must write yourself shrinks.
- Stock selection can use the built-in selection module to tick price-volume and chip (institutional/shareholder flow) conditions; the speaker says this covers 80% of what you would imagine for stock selection, and screening for limit-up next-day trades needs no code at all.
- The position control program only needs a per-order amount and runs on three variables: the entry condition, the exit condition and the order size; write it once and copy it into strategies with different logic.
- Entry and exit conditions are each written as a function returning True or False, so they can be swapped and combined like building blocks; people who cannot code can ask someone to write them, and the position management program does not need to change.
- After backtesting 6 months, a strategy built from simple blocks currently looks like it has positive expectancy; continuing to fine-tune the selection, entry and exit blocks and accumulating multiple sets makes it easier to find a fixed profit pattern.

## Section summaries

### 2:05 Limit-Up Next-Day Trading and the Stock Selection Module

Using the limit-up next-day trade (a stock hits limit-up today and is shorted the next day) as the example, the speaker does not write his own stock selection code but uses the built-in selection module to tick price-volume and chip conditions, saying this covers 80% of what you would imagine for stock selection. The demo filters out stocks with volume under 1000 lots, limits the price to between 10 and 150, and requires a limit-up yesterday, without writing a single line of code.

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

### 5:05 The Three Variables of the Position Management Program

Position management only needs a per-order amount and runs on three variables: the entry condition, the exit condition and the order size. With no position and the entry condition met, it shorts; with a position and the exit condition met, it covers. Write it once and it can be copied and reused repeatedly.

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

### 7:35 Writing and Calling the Entry Condition Function

The entry condition is written as a separate function that returns True or False to say whether it holds, and you note the function name so it can be called. The demo uses whether the stock can be traded intraday (day-trade eligible) as the entry condition; others, such as the closing price being above the 5-day moving average, can be added below it.

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

### 9:15 The Exit Condition Function and Block-Style Combination

The exit function must also return a logical value. The demo includes exiting at a specified time, and keeping the current price no more than 1.08 times the reference price (a gain of no more than 8%) as protection against limit-up; multiple conditions can be chained with or. Entry and exit functions work like building blocks that can be written by someone else and recombined repeatedly. For example, you can write another entry condition that shorts only when the closing price is below the opening price, and to use it you just change the function name being called in position management.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep15/?ref=agent#s-3) | [YouTube 9:15](https://www.youtube.com/watch?v=GvsBj7zTOrQ&t=555s)

### 14:05 6-Month Backtest Results and Further Optimization

Backtesting limit-up stock selection over the most recent 6 months, with at most one entry per day, the result currently looks like positive expectancy. Going forward, you can refine the selection, entry and exit blocks, accumulate multiple sets of entry, exit and selection strategies, and combine them yourself to find a fixed pattern that profits easily.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep15/?ref=agent#s-4) | [YouTube 14:05](https://www.youtube.com/watch?v=GvsBj7zTOrQ&t=845s)

---

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

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