A 30-Period Moving Average Trend-Following Demo
Summary
This compact trading demo uses a 30-period moving average to determine direction. When a completed bar closes above the average, it enters or switches to a long position; when the close falls below the average, it enters or switches to a short position. The example polls market data, computes the average, and checks for a new bar before acting, so the basic signal is evaluated once per bar rather than on every price update.
The document provides source logic and a position amount parameter, but no market, timeframe, backtest period, transaction-cost assumptions, or performance results. It does not describe protective stops, position sizing tied to risk, or handling of execution failures. A single moving-average rule is easy to understand, but it can switch repeatedly in sideways markets and incur costs or slippage. The example is best read as a minimal illustration of trend-following entries and reversals, not as evidence of a tested trading system.
Key ideas
- The demo uses a 30-period moving average as its directional filter.
- A bar close above the average triggers a long position, while a close below it triggers a short position.
- The logic checks for a new bar before evaluating a position change.
- No backtest results, trading costs, stop rules, or detailed 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.