# Day 4. How to Explain to an AI Assistant What to Build — and Verify the Result

> Today's goal is to turn your paper from yesterday (one sentence + four rules + a flowchart) into a **working bot on a test account**, **without writing a single line of code yourself**. This will feel strange for an old-school programmer. For 2026, this is the norm.

---

## Why Not to Write Code by Hand Today

The great truth of 2026: **writing code by hand is an outdated skill for most tasks**. Claude, GitHub Copilot, Cursor, and Gemini Code Assist write code faster and cleaner than the average programmer — if you give them a **clear task**.

The most valuable thing in modern development is **not syntax**. Syntax is now a commodity. An AI assistant can write you a function in Python, Rust, Go, or anything else — in seconds. For less than the cost of an hour of your time.

What **cannot be delegated** to an AI:

1.  Defining the task. The AI doesn't know what **you** want.
2.  Verifying the result. The AI doesn't know if the code works in your specific environment.
3.  Architectural decisions. The AI won't choose what to build for you in the first place.
4.  Iteration based on data. The AI isn't sitting at your screen and seeing that the bot is behaving strangely.
5.  Business decisions. The AI doesn't know when you should shut down an experiment.

In other words: **defining**, **verifying**, and **iterating** are on you. Everything else is for the AI.

This day is about these three things. Not about code.

Today:

1.  A prompt template for an AI assistant — how to explain what to build.
2.  Which AI to choose (Claude Code, Cursor, Copilot — a brief overview).
3.  How to read the result and not be deceived by the AI's confident voice.
4.  Where AIs typically make mistakes in algorithmic trading tasks.
5.  How to iterate — what to change in the prompt if the bot isn't behaving as expected.
6.  Homework — build your **first working bot** on a test account.

By the end of the day, you will have code that you didn't write by hand — but you will **fully understand** what it does and why.

---

## Which AI Assistant to Choose

For our task, there are several options. All are viable, and each has its strengths.

### Claude Code (from Anthropic)

-   **Strong point:** Deep understanding of tasks described in natural language, excellent for complex prompts.
-   **Weak point:** No native IDE integration (runs from the terminal).
-   **Price:** $20/month subscription.
-   **When to choose:** If you're comfortable working in the terminal, if the task requires in-depth discussion.

### Cursor

-   **Strong point:** Integrated into an IDE, convenient in-code dialogue, can edit code live.
-   **Weak point:** Paid (the free tier is limited).
-   **Price:** $20/month after the free requests are used up.
-   **When to choose:** If you're used to an IDE, if you want to refactor iteratively.

### GitHub Copilot

-   **Strong point:** Inexpensive, integrated into VSCode/JetBrains.
-   **Weak point:** Less "intelligent" on complex tasks, makes mistakes more often.
-   **Price:** $10/month or free for students and open-source maintainers.
-   **When to choose:** If you're on a tight budget, if the task is simple.

### The Free Path — Regular Claude or ChatGPT via the Website

-   **Strong point:** $0.
-   **Weak point:** No IDE integration, requires copy-pasting.
-   **When to choose:** For the very beginning, to understand the process. Then switch to a paid plan.

**For this day:** pick **any** of them. The principle is the same — you formulate the task, read the result, and iterate. The specific tool is a detail.

If you have no other options, open claude.ai (or chat.openai.com). It's free for basic use and sufficient for your first bot.

---

## Prompt Template for Building the Bot

A prompt is your **technical specification** for the AI. The clearer it is, the better the code.

### Prompt Structure (Universal)

A good prompt consists of six parts:

```
[Context]
Who I am and what I'm building, in one sentence.

[Task]
What exactly needs to be done right now, specifically.

[Input Data]
What data sources, what APIs, what formats.

[Logic]
A clear description of the rules we wrote down on paper.

[Constraints]
What the code should NOT do. What to avoid. What the risks are.

[Output Format]
What result we expect from the AI — a single file, several files, with or without tests, with or without comments.
```

Six blocks. Each is important in its own way. Half of the bad responses from an AI are because the prompt is bad, not because the AI is dumb.

### How to Fill in the Blocks for Our Bot

Take your paper from Day 3 and **rewrite** it into the prompt format.

**Context:**

```
I am developing a trading bot for the Binance crypto exchange for educational purposes. 
I am running it on the Binance Spot Testnet (testnet.binance.vision), 
not with real money. I am using Python 3.10+, 
the python-binance and pandas libraries. I have already configured my API keys in a .env file.
```

**Task:**

```
Write the skeleton of a trading bot: functions for fetching candles, generating signals, 
managing positions, and logging trades. The main loop should run once every N minutes. 
Testing is **not needed** for now — we are making a minimum viable version.
```

**Input Data:**

```
- API: Binance Spot Testnet via the python-binance library
- Candles: BTC/USDT pair, 1-hour timeframe, the last 100 candles
- Key source: BINANCE_API_KEY and BINANCE_API_SECRET environment variables 
  via python-dotenv
```

**Logic** — this is the most important part. Copy your four rules here verbatim:

```
STRATEGY — an educational trend-following strategy, simple for the first version:

ENTRY: open a BUY position when:
1. The fast SMA (20 bars) has crossed the slow SMA (50 bars) from bottom to top 
   on the last closed candle.
2. And the last volume is higher than the average volume over 20 candles.
3. And there is no open position.

EXIT: close the position when:
1. The price reaches +2% from the entry price (take-profit), OR
2. The price drops by -1% from the entry price (stop-loss), OR
3. More than 24 hours have passed since entry (time-stop).

RISK:
1. Position size = 1% of the USDT balance (fixed size for simplicity).
2. A maximum of one open position at a time.

EMERGENCY STOP:
1. If three consecutive API calls return an error — the bot writes "EMERGENCY STOP" 
   to the log and terminates.
```

**Constraints** — what NOT to do:

```
- Do not use a real account. Always use testnet=True.
- Do not select or optimize parameters — all numbers are chosen manually for the first version.
- Do not add complex indicators other than SMA — keep it simple.
- Do not implement multithreading or asynchronicity — a regular synchronous loop is sufficient.
- Do not use external libraries for strategies (backtrader, vectorbt) — write from scratch 
  using python-binance and pandas.
```

**Output Format:**

```
A single file, bot.py.
Structured, with comments in Russian.
Log each trade to a trades.csv file (timestamp, side, price, qty, balance).
Log general events to stdout.
At the bottom of the file, include an `if __name__ == "__main__":` block that runs the main loop.
```

### The Complete Prompt Assembled — This Is What You Copy into Claude/Cursor

Combine all six blocks into one long text. You'll get about 400-600 words. This is your **technical specification**.

Most people write "write me a trading bot" — and are then surprised when the result is unsuitable. With our template, the result will be 80% correct on the first try.

---

## How to Read the Output from the AI

An AI often states things that are **actually incorrect** with a confident voice. This is especially dangerous in trading, where a mistake costs real money (even on a test account — you'll lose educational time).

Your job is **not to understand every single line**, but to verify **what the code does at a logical level**.

### Seven Things to Check

**1. Is `testnet=True` used?**

Open the code and find the Binance client initialization. It should look something like this:

```python
client = Client(API_KEY, API_SECRET, testnet=True)
```

If **`testnet=True`** is not written or it says **`testnet=False`** — **stop**. This means the code will run on a real account. Re-prompt the AI: "fix this, I am only working on the testnet."

**2. Where is the entry rule?**

Find the function that decides whether to enter a trade. Read its logic out loud. It must match your rule from Day 3. If it doesn't, ask the AI to rewrite it.

**3. Where is the exit rule?**

Find the exit function. It should close the position based on any of the three conditions: take-profit, stop-loss, or time-stop. If it only has one, ask it to add the others.

**4. Where is the emergency stop?**

Find the error handling. If the code crashes on any API error, that's bad. There should be an error counter and a condition to exit after N consecutive errors.

**5. Where are the trade logs?**

Find where `trades.csv` or similar is being written. If it only logs to standard output, say "add a file log so I can analyze it later."

**6. What about the configuration?**

Parameters (SMA period, take-profit/stop-loss percentages) should be **at the beginning of the file as constants**, not scattered throughout the code. If they are scattered, ask the AI to "move all settings to a single CONFIG section at the beginning."

**7. What about tests?**

In the first stage, there **may not be any tests**. This is normal. But a **test run** should be easy — the functions for fetching candles and generating signals should work **separately** from the live loop. This will allow you to check the logic without running the bot against the real API.

### How to Discuss Code with the AI

After the AI has generated the first version — **do not run it immediately**. Open a dialogue with the AI:

-   "Explain in simple terms what function X does."
-   "What will happen if the API returns an empty array of candles?"
-   "What if a position was opened, but the price immediately dropped by 5%?"

The AI will answer. If the answer matches what you intended, great. If not, say "fix it, it should be like this."

After 3-5 iterations of discussion, you will have code that **you understand** — even if you didn't write a single line.

---

## Where AI Typically Makes Mistakes in Algorithmic Trading Tasks

Experience shows that AI assistants in our niche make **the same mistakes as beginner programmers**:

1.  **Forgetting `testnet=True`.** This is the most dangerous one. Always check.

2.  **Using the last, unformed candle for decisions.** The candle for the current hour changes every second. You cannot make a decision based on it. It should be the "last **closed** candle." If this clarification is missing, ask the AI to add it.

3.  **Not checking the API response.** If the exchange returns an error, the code must handle it, not pretend everything is fine.

4.  **Opening a position without checking the balance.** If there isn't enough USDT in the account, an attempt to buy will cause an error. There must be a check before every order.

5.  **Not accounting for fees.** A +2% take-profit with a 0.1% entry fee + 0.1% exit fee is actually +1.8%. The AI often forgets to mention this.

6.  **Hard-coding parameters into the logic.** The SMA period is written as `20` directly in the formula, not as a constant. This is bad for future iteration.

7.  **Ignoring race conditions.** If the bot sleeps for 5 minutes between ticks, a lot can happen in that time. Good code takes into account that the state of the world could have changed.

All seven are typical. The AI doesn't make them on purpose. It's just that such tasks are statistically rare in its training data. Your duty is to catch them **before** launch.

---

## How to Iterate

A bot never works on the first try. That's normal. What's **not normal** is changing the prompt chaotically, poking at random places.

The correct iteration process:

1.  **Run the bot.** Let it work for 1-2 hours. Notice something strange.
2.  **Write down what's strange.** One specific observation. Not "the bot is bad" — "the bot didn't close the position after 24 hours as it should have according to the time-stop."
3.  **Open a dialogue with the AI.** Copy the part of the code that is supposedly responsible for this behavior. Ask "why isn't this working?"
4.  **The AI explains or suggests a fix.** Read it, understand it.
5.  **Apply one change.** Not three. One.
6.  **Run it again.** Wait another 1-2 hours. Check if the strange behavior has disappeared.

This is slow. This is correct. **One iteration cycle = one hypothesis**. This is how all professionals work. The chaos of changing ten parameters at once is the path of a beginner.

---

## Common Mistakes for Today Specifically

1.  **Copying the code from the AI and running it without looking.** The most common mistake. The seven items from the list above are mandatory checks. Without this, you're not a developer, just someone who runs other people's code.

2.  **Asking the AI to "optimize the strategy."** The AI doesn't know what's good for **your** strategy. If it adjusts the parameters based on its own opinion, it will overfit them to historical data, and you'll get a curve-fit. The parameters are your decision, based on backtesting, not on the AI's opinion.

3.  **Accepting the first version of the code.** A good workflow involves **3-5 iterations** of discussion. The first version is rarely perfect. Don't rush to run it.

4.  **Delegating **architectural** decisions to the AI.** "What strategy should I choose?" — no. That is **your** decision, based on your profile and capital (see Day 2). The AI can provide a neutral overview, but the **choice** is yours.

5.  **Not keeping a log of prompts.** In two weeks, you won't remember why you asked the AI to change the exit function. Create a `prompts.md` file where you save all important prompts — it will also serve as your code documentation.

6.  **Thinking that code from an AI is "not your" code.** Legally — maybe, depending on the assistant's license. **Morally** — it is **your** code, because you defined the task, verified it, and iterated on it. Programming is about **formulation**, not **typing letters**.

---

## Today's Assignment

This is the most practical day. By the end of the evening, you should have a **running bot on a test account**.

Checklist:

-   [ ] Chose an AI assistant (Claude / Cursor / Copilot / free Claude via website)
-   [ ] Assembled a complete prompt using the six-block template (context / task / input / logic / constraints / format)
-   [ ] Received the first version of the code from the AI
-   [ ] Went through the seven checks from the lesson (testnet, entry, exit, emergency stop, logs, config, tests)
-   [ ] Went through 2-3 iterations of discussion with the AI (minimum)
-   [ ] The bot has **started** and has been running on the Testnet for 1+ hour
-   [ ] The bot has made **at least one** trade (more if you're lucky)
-   [ ] A `prompts.md` file has been created, and key prompts have been saved in it

Send a short message to the Telegram channel:

```
Day 4 — done.

AI used: ___________
How many iterations it took to get a working bot: ___________
The most surprising thing the AI did well in the code: ___________
The most surprising thing the AI did poorly in the code: ___________
```

---

## What's Next for Tomorrow

Tomorrow is the last day. The most important one from a **long-term** success perspective. You have a running bot, you've made a few trades — but this means **nothing** statistically. Tomorrow, we'll figure out how to **measure** the bot's performance honestly (not just "I like it / I don't like it"), how to iterate **based on data**, not emotions. And how to make the decision to "continue or quit."

At the end of Day 5, I'll tell you what we have **next**, for those who seriously want to go deeper. But that will be at the **very end**, with no pressure.

See you tomorrow.

---


# Homework — Day 4

> The main goal for today is to get a **running bot** on a test account **without writing a single line of code by hand**. The AI assistant writes all the code; you set the task and review it.

## Checklist

- [ ] **AI assistant selected** (Claude / Cursor / Copilot / free Claude via website)
- [ ] **Full prompt assembled** based on the six-block template
- [ ] **First version of the code received** from the AI
- [ ] **Seven checks passed:** testnet=True / entry rule / exit rule / emergency stop / logs / config at the top / ability to test run
- [ ] **2-3 iterations** of discussion with the AI conducted (improvements, fixes, explanations)
- [ ] **Bot has started** and is running on Testnet for at least 1 hour
- [ ] **At least one trade** made (or at least a signal registered in the log)
- [ ] **`prompts.md` file** created, with key prompts saved for future iteration

---

## Prompt Template for Copying

> Replace everything in `___` with your data from day three. This will become **your** technical specification for the AI.

```
[CONTEXT]
I am developing an educational trading bot for the Binance crypto exchange.
I am running it on the Binance Spot Testnet (testnet.binance.vision),
not with real money. I am using Python 3.10+, and the python-binance and pandas libraries.
I already have my API keys set up in .env via python-dotenv.

[TASK]
Write the skeleton of a trading bot: functions for fetching candles, generating signals,
managing positions, and logging trades. The main loop should run once
every N minutes (I will specify N later). This is a minimum viable version.

[INPUT DATA]
- API: Binance Spot Testnet via python-binance
- Candles: pair ___, timeframe ___, last 100 candles
- Key source: environment variables BINANCE_API_KEY and BINANCE_API_SECRET

[LOGIC]
Strategy — ___ (trend-following / counter-trend / ...).

ENTRY: open a position when:
1. ___
2. ___
3. And there is no open position.

EXIT: close the position when (any of the following):
1. The price reaches +___% of the entry price (take-profit)
2. The price drops by -___% of the entry price (stop-loss)
3. More than ___ hours have passed since entry (time-stop)

RISK:
1. Position size = ___% of the USDT balance
2. Maximum of one open position at a time

EMERGENCY STOP:
1. If three consecutive API calls return an error, the bot writes "EMERGENCY STOP" to the log
and terminates.

[CONSTRAINTS]
- Do not use a real account. Always use testnet=True.
- Do not tune or optimize parameters — all numbers are fixed.
- Do not use complex indicators.
- Do not use external libraries other than python-binance, pandas, and python-dotenv.
- Use only the last **closed** candle for decisions, not the current one.

[OUTPUT FORMAT]
A single file, bot.py.
Structured, with comments in English.
Logs of each trade to a trades.csv file (timestamp, side, price, qty, balance).
Logs of general events to stdout.
All settings (periods, percentages, timeframe) at the beginning of the file as CONFIG constants.
At the bottom, an `if __name__ == "__main__":` block that starts the main loop.
```

---

## Seven Checks for the AI's Output

> Don't skip a single one. This is your **guarantee** that the bot won't do something disastrous.

1.  **`testnet=True`** in the client initialization — is it there?
2.  **Entry rule** — does it match what you have on paper?
3.  **Exit rule** — are all three conditions (take-profit / stop-loss / time-stop) present?
4.  **Emergency stop** — is there an API error counter, and does the bot exit after N errors?
5.  **Trade logs** — are they being written to a CSV file?
6.  **Config** — are all parameters at the beginning as constants, not scattered throughout the code?
7.  **Test run** — can the functions for fetching candles and generating a signal be called **separately** from the live loop?

If **any** check fails, send the AI a screenshot / code snippet and ask it to fix it. Do not run the bot until all seven checks have passed.

---

## Prompts for Iterations (Examples)

After the first version of the code, start a dialogue. Here are some phrases that work:

- "Explain in simple terms what the [name] function does."
- "What will happen if the API returns an empty array of candles?"
- "What if the bot opened a position, and the internet connection was lost for 5 minutes?"
- "I noticed that [specific behavior]. How can I fix this?"
- "Add handling for the case where [situation], it should [expected behavior]."
- "Rewrite the [name] function so that [clarification]."

---

## What to Write in `prompts.md`

Create a `prompts.md` file next to `bot.py`. Write the following in it:

```
## First prompt (day 4, date)
[your entire first prompt/technical spec]

## Iteration 1: fixing the exit logic
[what you asked to fix]

## Iteration 2: adding the emergency stop
[what you asked to add]

...
```

This file is your code's **documentation**. In two weeks, you won't remember why the exit function is designed this way, but `prompts.md` will have the exact history.

---

## What to Send to the Group Chat

```
Day 4 — done.

AI used: ___________
How many iterations it took to get a working bot: ___________
The most unexpected thing the AI did WELL in the code: ___________
The most unexpected thing the AI did POORLY in the code: ___________
```

---

## If You're Stuck

**Is the AI giving you code that won't run?** Copy the error verbatim into the chat. Say: "here's the error, fix the cause." In 90% of cases, the AI will fix it.

**Did the bot start but is silent — doing nothing?** This is normal for an educational strategy. Signals are rare. Decrease the timeframe (e.g., from 1 hour to 15 minutes) for the **first test** — you'll get more trades and see that the bot is alive faster. You can change it back later.

**Did the bot make a trade, but entered and immediately exited at a loss?** This is **also** normal — it's running on paper-trading, educational parameters. Today's goal is to **get it running**, not to make a profit. Profit comes after months of iteration.

**Is the AI insisting on something you disagree with?** Remember: **the architecture is your decision**. If the AI says, "let's add Bollinger Bands for reliability," but you didn't choose a counter-trend strategy, say no. It's your bot, not its.

---

Until tomorrow.