A Double Moving Average Crossover Strategy for Long and Short Signals
Summary
This strategy uses two simple moving averages of closing prices to generate directional trades. It compares a faster average with a slower one on each bar and identifies a bullish crossover when the fast average moves above the slow average, or a bearish crossover when it moves below. The fast and slow windows are configurable, with defaults of 10 and 20 bars.
On a bullish crossover, the strategy opens a long position if flat, or closes a short and opens a long position. On a bearish crossover, it opens a short if flat, or closes a long and opens a short. The example submits orders at the current bar's close price and uses one unit per order. It provides no backtest results, transaction cost assumptions, position sizing rules, or risk controls, so profitability and live execution behavior cannot be inferred from the code.
Key ideas
- The strategy generates signals from crossovers between fast and slow simple moving averages.
- A bullish crossover opens a long position or reverses an existing short position.
- A bearish crossover opens a short position or reverses an existing long position.
- The moving average windows are configurable, with defaults of 10 and 20 bars.
- The example gives no performance evidence or explicit risk management rules.
Tags
From a private course collection; the original is not published.