A computer can only follow rules that are exact. Words like strong, near or big mean nothing to it. By the end of this lesson, you'll know how to find the vague words in your rules, and turn each one into a number. You'll also know the questions every rule needs answered before it can run on its own.
1 of 8
What you'll learn
- Give every vague word a number. A computer can't measure words like strong or near.
- Close every gap. Leave one, and the coder picks an answer the program then trades.
- Write an else for every if. Cover open trades, unfilled orders and the end of day.
- Write the rules as plain steps. This pseudocode lets a person check the logic first.
- Run the rules once. Exact rules give the same entry, stop and target.
Exercise
- Take your own written rules.
- Underline every word a computer couldn't measure, and rewrite each one with a number.
- Then answer the four “else” questions: already in a trade, entry not filled, stop and target in one candle, end of day.
Quick check
1. A rule says “buy near support”. What happens when it's coded?
2. Which of these is exact enough for a computer?
3. One candle touches both the stop and the target. Why do the rules need to cover this?
0 of 3 answered.
Finished this lesson?
Tick it off and keep your place
Read the full notes
To automate a set of rules, every vague word needs a number a computer can measure, and every “if” needs an answer for the cases people usually handle without thinking, such as an open trade, an unfilled order or the end of the day.
- A computer does exactly what it's told and never fills a gap with judgement. A vague rule doesn't stop the code from running: the coder picks an answer, and the program trades it. See The two-person test.
- Find the vague words and give each a number, for example: “strong trend” → close above the 20-candle The average of the last few closing prices, worked out again on every candle and drawn as a line.More in the glossary; “big candle” → range at least 2× the last 20 candles' average; “near” → within 4 The smallest step a price can move. On many stock index futures that’s 0.25 of a point.More in the glossary; “early” → times plus a time zone. Examples of the kind of answer, not settings to use.
- Every “if” needs an “else”: a new signal while in a trade; an entry that doesn't fill; An order that closes a trade if price reaches a level you set against it. It aims to limit the loss, but in a fast market it can fill at a worse price.More in the glossary and An exit order that closes a trade when price reaches a level you choose in your favour.More in the glossary both inside one One bar on a price chart. It shows where price opened and closed, and the highest and lowest it reached, in one stretch of time.More in the glossary; the end of the day and Moving from a futures contract that’s about to expire to the next contract month.More in the glossary.
- Write the exact rules as Rules written step by step in plain words laid out like code, so a person can check the logic before anyone writes real code.More in the glossary so a person can check the logic before any real code is written. Code for them is taught in Coding strategies in Pine Script and Writing entry and exit rules in Python.
- Made-up: entry 5,018.25, stop 1 tick below a 5,010.50 low = 5,010.25. Risk 8 points = 32 ticks = $40 a contract on the A small futures contract on the S&P 500, traded at CME Group. Each point is worth $5, and its smallest step of 0.25 is worth $1.25.More in the glossary; target 2× risk = 5,034.25.
- Answer to the drill: stop 5,015.50; 6 points = 24 ticks = $30.
Worked example
Made-up numbersRunning exact rules once
Made-up numbers · Micro S&P 500 · 1 tick = 0.25 points = $1.25
- Entry: 5,018.25.
- Lowest low of the last 5 candles 5,010.50, so the stop is 5,010.25.
- Risk: 8 points = 32 ticks = $40 a contract.
- Target: 5,018.25 + 2 × 8 = 5,034.25.
Exact rules give everyone the same entry, stop and target.
Your turn
DrillMade-up numbers · Micro S&P 500 · 1 tick = 0.25 points = $1.25 · entry 5,021.50 · lowest low of last 5 candles 5,015.75 · stop 1 tick below it
Trading is risky. You can lose money, and automated trading can lose like any other trading. This lesson explains how things work. It isn’t advice.