Episode 7 · AI Trading · Building a Complete Trading System

The five-part prompt for traders: role, data, limits, output, check

A prompt frame that keeps the model on your data: a time lock, a source for every number, two conditional scenarios and a self-check, run three times.

A prompt is everything you give the model in one turn: instructions and data. The major vendors’ prompting guides agree on the basics: be specific, give the model a role, show examples, and separate the parts with tags or headings. They also agree that a long block of data goes early and the question goes last. With inputs of roughly 20,000 tokens or more, putting the question at the end measurably improves answers, most of all with several documents.

A useful test: hand the prompt to a colleague with little context. If they are confused, the model will be too. Explaining why you want something also helps, because the model generalises from the reason.

One more point: some current models ignore the temperature setting entirely. If you want stable answers, rely on a clear prompt and clear data, not on tuning parameters.

The five-part frame

Before sending any prompt, answer five questions:

  1. Role: who is the model, and who does it serve?
  2. Data: which data, up to what time?
  3. Constraints: what is forbidden, what is required?
  4. Output: what shape does the answer take?
  5. Check: how will you know the answer is right?
Part Question Example with candle data
1. Role Who is the model? “You describe price data for a new trader; you don’t predict and don’t give orders.”
2. Data Which data, up to when? 120 closed H4 XAUUSD candles exported from an MT5 demo; file name, time zone of the time column, close time of the last candle
3. Constraints Forbidden, required? The time-lock block; only the pasted data; no invented numbers; for lot sizing, max 1% risk, round down to 0.01
4. Output What shape? Max 3 sentences on trend; a table of levels with a “source candle” column; 2 scenarios, each with a confirmation and an invalidation condition; the 3-line tail
5. Check How do you know? “Before answering, list every number and the date/time of the candle it comes from. Missing data: write NOT ENOUGH DATA.”

Wrap each part in a pair of tags so the model knows what is data and what is instruction. Any tag names work, as long as you use the same ones in every prompt. The data (a CSV, one candle per line) is usually the longest part, so it goes right after the role. The question always goes last.

<role>...</role>
<data source="data/xauusd_h4.csv, MT5 demo" until="2026-11-11 02:00 UTC">
...120 closed candles...
</data>
<constraints>...time lock...</constraints>
<output>... + 3-line tail</output>
<check>...</check>
<question>...</question>   (always last)

Ask for description and checks, not predictions. Write “describe the trend and two scenarios with confirmation conditions”, not “will gold go up or down”. Each scenario gets two conditions: a confirmation you can see on the chart (“an H4 candle closes above X”) and an invalidation that shows the scenario was wrong. That gives you something to watch, not a promise about price.

The 3-line tail. When the model answers in prose for you to read (a chart description, scenarios, a view after a news release), end the output section with three fixed items:

  1. What would prove the main view wrong: a price level or an event you can check on the chart, such as “an H4 close below X”.
  2. The three biggest risks to the view, each pointing to the candle or data behind it, or NOT ENOUGH DATA.
  3. A last line copied verbatim: “This is analysis, not an order.”

The first two force the model to argue against its own view instead of only listing reasons for it. That is different from a scenario’s invalidation: the invalidation belongs to each scenario, the tail to the main view. The third reminds the reader, possibly you a week later, that the decision is yours.

Prompts that must return exactly one JSON object or a fixed template for code to check get no tail: any extra text breaks the format check. There, code checks the answer and you still decide.

The time lock and a source for every number

A model has no live prices unless it is given a lookup tool or data. So you take candles and prices from your MT5 demo, paste them with their time, and never ask “what’s the gold price now” in a chat with no lookup tool. Put this block at the top of the constraints in every analysis prompt:

Decision time: 2026-11-11 02:00 (UTC).
Use only data timestamped <= this time. Do not infer anything after it.
Every number must cite its source (file name + candle date/time, or URL + access time).
No source: write "unverified".
If the data is not enough to conclude, write NOT ENOUGH DATA and say what is missing.

Two details trip people up with MT5 data.

The time on each candle is its open time. The bar’s time field is the period start. An H4 candle stamped 08:00 closes at 12:00. The decision time must be after the last candle’s close, and the candle still forming must be deleted from the data.

MT5 shows quotes in the broker server’s time zone. Assume the exported time column is server time until you have checked. To find the offset, while the market is open, read the latest quote time in Market Watch and your own clock at the same moment (right-click Market Watch to show the time column if needed). Example: Market Watch shows 03:15 while your clock shows 01:15 UTC, so server time is UTC+2. The H4 candle stamped 00:00 closes at 04:00 server time, 02:00 UTC: at 01:15 UTC it is still forming, so delete it. The last remaining candle is the 20:00 one from the day before. If you export after 02:00 UTC, the 00:00 candle has closed and 02:00 UTC is the earliest decision time you can write. Some brokers shift the offset with the seasons, so check on every export.

Six ways to reduce made-up answers

A hallucination is a model writing something false, or absent from your data, as if it were true. For a trader it’s usually a price level, a news figure or a backtest statistic that isn’t in what you provided.

Technique Sentence to put in the prompt Use when
Allow “I don’t know” “If the data is not enough to conclude, write NOT ENOUGH DATA and say what is missing.” Every analysis prompt. This alone cuts false information sharply
Quote first, analyse second “Quote the relevant sentences verbatim inside <quotes>, numbered; analyse only what you quoted.” Long documents (20k+ tokens): central bank statements, backtest reports
Verify with quotes “After writing, find a supporting quote for each claim; if there is none, delete the claim and leave [] in its place.” News summaries, report reading
Restrict outside knowledge “Use only the data in <data>, not general knowledge.” Candle analysis, trade journals
Best-of-N No sentence: run the same prompt several times, each in a fresh session, and compare Where the runs disagree, something may be invented
Ask it to check itself Paste the previous answer into a new prompt: “Check each claim below against the original data; which have no basis?” Before using the result in a plan

When the model needs fresh or rare facts, enable search (grounding). When it needs to compute or count, enable code execution. These techniques reduce hallucinations a lot; they do not remove them. Lot sizing is deterministic: ask for every step, recompute on a calculator, round down to 0.01. No prompt technique replaces that check.

Three ways the future leaks in

Look-ahead means using information that could not have been known at the decision time. With AI there are three separate layers.

A. Code that looks ahead. In Pine Script v6, request.security (data from another timeframe) called with lookahead_on and no [1] offset returns future data on historical bars. Public scripts that do this get moderated. The [1] offset (the previous, closed bar) and lookahead_on go together; dropping either one is wrong. Signals computed on an unclosed bar can repaint: change or vanish when the bar closes, so history looks better than live trading. barstate.isconfirmed waits for the close, at the cost of a later signal.

// Wrong: on historical bars the H4 close appears before that H4 bar has closed
h4CloseBad = request.security(syminfo.tickerid, "240", close, lookahead = barmerge.lookahead_on)
// Right: the closed H4 bar, [1] offset together with lookahead_on
h4Close = request.security(syminfo.tickerid, "240", close[1], lookahead = barmerge.lookahead_on)

B. The model already “knows” the outcome. When a model scores old headlines or old charts for a backtest, the test period may overlap its training data: it may already know how price moved after the news. Its general knowledge about the asset also distorts the scoring. In one test on US stocks, hiding company names actually improved in-sample results, meaning the distraction effect was larger than the look-ahead effect. So hide the asset name and dates when asking a model to judge old data, and only trust results from after the model’s training cutoff. (That test covered US equities; there are no equivalent numbers for gold, forex or crypto.) Practising your own decisions on a replay with dates hidden follows the same idea.

C. Invented current data. Without a lookup tool, a model can invent prices and news. Block it with the time lock, data you paste yourself, and a source for every number.

Layer Example Blocked by
A. Code A multi-timeframe indicator using lookahead_on without an offset Require close[1] with lookahead_on and barstate.isconfirmed; make the model list every request.security call before giving code
B. Model memory Asking a model to re-score old news or charts for a backtest Hide asset and dates; trust only post-cutoff periods; compare against a rule written in code
C. Invented numbers “What’s gold now?” with no lookup tool Paste data with times; time lock; unsourced numbers marked “unverified”

Fixing ten bad prompts

Cover the last two columns, guess what’s wrong, then read on. The three most common faults: asking for a prediction instead of a description, missing data with a timestamp, and no check.

# Bad prompt Why it’s bad Better prompt
1 “Will gold go up or down this week?” Asks for a prediction; no data; no time; the model may invent a price “Based on the 120 H4 XAUUSD candles I pasted (last candle closed 2026-11-11 02:00 UTC), describe the trend and 2 scenarios, each with a confirmation and an invalidation condition. No predictions. End with 3 items: (1) what would prove your view wrong, as a price or event checkable on the chart; (2) the 3 biggest risks to the view, each citing a candle or data, or NOT ENOUGH DATA; (3) a last line copied verbatim: This is analysis, not an order.”
2 “Write me a gold bot that makes a lot” No spec; vague goal; tends to produce martingale code that grows the lot after each loss Write a spec first, review each condition, then ask for an EA used only for backtests and demo
3 “Write a multi-timeframe indicator that doesn’t repaint” No Pine version, no look-ahead rule, no check Pine v6, close[1] with barmerge.lookahead_on, signals with barstate.isconfirmed; make the model review every request.security call and report before giving code
4 “Is this backtest good?” (equity curve screenshot) No numbers or test conditions; the model praises the shape Paste the full report: period, fees, spread, tick model; give it the role of finding weaknesses, not praising
5 “Summarise yesterday’s Fed news” (no web tool) The model may invent content and figures Paste the statement with source and time; or enable search and require a URL and access time per point
6 “500 USD account, can I trade 0.5 lot gold?” No stop, so risk can’t be computed “Balance 500 USD, risk 1% = 5 USD, stop 6 USD away, XAUUSD 1 lot = 100 oz. Compute the lot, round down to 0.01, show the working; below 0.01 lot conclude no trade.”
7 “NEVER use future data!!!” Shouts without a reason “Don’t use data after the candle being evaluated, because the backtest would show results that are impossible in real time.”
8 “Gold right now: buy, wait or avoid?” Still a prediction, wrapped in three choices; untestable before price moves “Based on the 120 H4 candles I pasted (last close 2026-11-11 02:00 UTC), describe the structure and 2 scenarios with confirmation and invalidation. Don’t advise buy, wait or avoid.” + the full 3-item ending from row 1
9 “You are a gold expert with 30 years’ experience, give me your view for this week” A borrowed-authority role adds no data or real experience; “your view for this week” is a prediction A task role: “You describe price data for a new trader; you don’t predict or give orders”, then continue as row 1
10 “Rank gold, EURUSD and BTC for the next 12 months” A long-range prediction: gradeable only after 12 months; the model has a training cutoff; a ranking reads like a buy list “From the 3 closed D1 CSV files attached (source, time zone, from … to …), use the code tool to compute for the PAST 12 months: the standard deviation of daily % close-to-close change (not annualised) and the maximum drawdown on closes, with the date and close of the peak and trough. Print the code you ran, and the row count and first and last date read per file; if you can’t run code, write CANNOT COMPUTE, don’t estimate. No ranking for the future.” + the 3-item ending

Row 6 by hand: risk 1% of 500 USD = 5 USD; on XAUUSD a 6 USD stop loses 600 USD per lot; 5 ÷ 600 = 0.0083, rounded down to 0.01 steps gives 0 lot. No trade with this stop. 0.01 lot would risk 6 USD, more than 5. A good answer says so instead of suggesting 0.01.

Row 7: give the reason instead of shouting in capitals. With some recent models, harsh wording like “CRITICAL: You MUST use this tool when…” makes them overuse the tool; plain “Use this tool when…” works better.

Rows 8 to 10 sound professional and still ask for predictions. “Buy, wait or avoid?” is “up or down?” in other words: the model must pick one piece of advice, and nobody can check it before price moves. A “30-year expert” persona gives the model no extra data or experience. Tests of 162 personas on 2,410 multiple-choice factual questions across nine open models found that, overall, adding a persona does not make answers more accurate, and that any single persona’s effect is largely random. A task role still helps define the job (“you describe data”); a prestige role only makes you trust the answer more than it deserves.

Row 10 turns the longest-range prediction into measurements on the past: the standard deviation (how far values swing around their mean) and the maximum drawdown (the deepest fall from a peak to a later trough). Each file has a few hundred daily candles, so let code compute it, and spell out the formula, because “volatility” or “drawdown” computed another way gives different numbers. Check by hand: the row count and first and last date must match your file, and Ctrl+F the trough date in the CSV to compare the close. Code computes, the model describes the table, you decide.

Write the tail in full inside the prompt. Typing just “3-line tail” means nothing to a model in a fresh conversation; that is the colleague test again.

Try it: 120 H4 candles, three runs

You need an MT5 demo account (never a live one), the trading-agent-lab folder and one AI tool. The model only reads data here; it connects to nothing and you decide. No passwords, account numbers or API keys go into the prompt: candle data doesn’t need them.

  1. Export. In MT5 demo, right-click Market Watch → Symbols → Bars tab, pick XAUUSD (the name varies by broker) and H4, click Request, then Export the CSV into data/.
  2. Clean. Open the file in a text editor. Delete the candle still forming (open time + 4 hours is later than the current server time). Keep the header row and the latest 120 closed candles.
  3. Fill in the template below, paste the candles into the data section, set the decision time, and save as prompts/xauusd-h4-v1.md in UTF-8 (in Notepad, Save as type “All files”, Encoding UTF-8, so it doesn’t become .md.txt).
  4. Run it three times, each in a fresh session so a run can’t see the previous answer, and save the answers as reports/prompt-test/run-1.md, run-2.md, run-3.md. In a chat app, use a new conversation each time (a temporary chat if the app has memory). In Claude Code, start in Plan mode and type Read @prompts/xauusd-h4-v1.md and follow its instructions exactly. Write the full answer to reports/prompt-test/run-1.md, then /clear before the next run. Approve the file write; refuse any package install or network command, which this exercise doesn’t need.
  5. Grade. Highlight every number. Ctrl+F the source candle’s date/time in the CSV; if the price on that row matches, mark it “sourced”, otherwise “unverified”. Note where the three runs disagree.
  6. Write your own demo plan before looking at what came next.
  7. About two trading days later (12 H4 candles), open the chart and grade whether the confirmation conditions were clear enough to check on the chart.

Don’t grade by which scenario happened. The model doesn’t know the future, and one scenario coming true proves nothing about the prompt.

You see Cause Fix
@ doesn’t list the prompt file claude started in the wrong folder, or the file isn’t saved /exit, cd to the project, check dir prompts, rerun
The file shows as xauusd-h4-v1.md.txt Saved with a hidden .txt Rename-Item prompts\xauusd-h4-v1.md.txt xauusd-h4-v1.md
Accented characters turn into ? Not saved as UTF-8 Save as again with Encoding UTF-8
A “current price” that isn’t in the file Layer C hallucination Mark it “unverified”; check the prompt says to use only the data section
<role>
You describe price data for a new trader. You describe what the data shows;
you do not predict and do not give buy/sell orders.
</role>

<data source="[FILE, e.g. data/xauusd_h4.csv exported from MT5 demo]" timezone="[TIME ZONE OF THE TIME COLUMN, e.g. server time = UTC+2]" until="[LAST CANDLE CLOSE TIME, UTC]">
[PASTE THE HEADER ROW AND 120 CLOSED CANDLES]
</data>

<constraints>
Decision time: [YYYY-MM-DD HH:MM] (UTC).
Use only data timestamped <= this time. Do not infer anything after it.
Every number must cite as its source the date/time of the candle it comes from,
copied exactly as in <data>. No source: write "unverified".
Use only the data in <data>, not general knowledge of [SYMBOL] prices at other
times, because I need conclusions I can check against this data.
If the data is not enough to conclude a point, write NOT ENOUGH DATA and say what is missing.
No orders, no position sizes.
</constraints>

<output>
1. The current trend in at most 3 sentences, each with the date/time of the candles behind it.
2. A table of 3 important levels: level | source candle (date/time) | why it matters.
3. Two scenarios (up, down). Each has a confirmation condition checkable on the
   chart (e.g. "a [TF] candle closes above X") and a condition that invalidates
   it. Do not say which will happen.
4. What this data cannot tell you (upcoming news, higher timeframes, the path of price inside a candle).
5. What would prove the view in item 1 wrong: a price or event checkable on the chart.
6. The three biggest risks to that view, each citing a candle or data; without basis, NOT ENOUGH DATA.
7. Last line, copied verbatim: This is analysis, not an order.
</output>

<check>
Before answering: list every number you intend to use and its source candle;
drop any number without one.
After writing: delete any sentence that uses information after the decision
time or has no basis in the data; confirm items 5, 6 and 7 are present.
</check>

<question>
Based on the data and constraints above, answer exactly as specified in <output>.
</question>

Version your prompts. When you change one, bump the version number and note why, and keep the results next to it.

Key takeaways

  • Five parts (role, data, constraints, output, check), long data early, the question last, and the full 3-line tail written out for prose analysis.
  • MT5 candle times are open times in server time: delete the forming candle and set the decision time after the last close.
  • Best-of-N only exposes disagreement. Three runs giving the same unsourced number still means “unverified”.
  • Multi-timeframe Pine: lookahead_on must go with close[1], plus barstate.isconfirmed against repainting.
  • A model may “remember” old data: hide asset and dates, and trust only results after its training cutoff.

Comments