A Single-Stock Strategy Using Five-Day and Twenty-Day Moving Averages
Summary
This introductory example presents a simple moving-average strategy for one Chinese-listed stock. It calculates the average closing price over the most recent five sessions and compares it with the average over twenty sessions. When the shorter average is above the longer one, the example targets a fully invested position; when it falls below, it targets no position. The code separates one-time strategy initialization from the bar-by-bar decision logic and uses target-position orders to express the desired holding.
The example describes a basic trend-following rule, but its implementation checks whether one average is above the other rather than detecting a crossover event. That means it may repeatedly issue the same target order while the condition persists. The document supplies no backtest, transaction-cost treatment, risk controls, or evidence of profitability. It also gives no rationale for the chosen stock or averaging windows, so those choices should not be understood as generally suitable.
Key ideas
- The example compares five-session and twenty-session moving averages of closing prices.
- It targets full investment when the shorter average is higher and zero exposure when it is lower.
- The code evaluates the relative levels each bar rather than detecting only the moment of a crossover.
- No backtest results, cost assumptions, or risk controls are provided.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.