A position rule must specify when to buy, sell or stay flat. Python comparisons and branches express that decision; loops apply it to several observations. This lesson builds a small signal rule and traces its output. You will later put the rule in a function and check it with tests.
Learning objectives. By the end of this note you should be able to:
- assign and combine numbers, strings and Boolean values;
- write an
if/elif/elsedecision; - repeat a calculation with a
forloop; - trace a short program and predict its output.
In this lesson
- Values, names and expressions
- Branch when the market state changes
- Repeat over observations
- A minimal mental model
- Trace the position decision
This lesson is part of a free topic. Create a free account, no card needed, to read it in full with worked examples and exercise solutions.
Read it free