Skip to content
All library documents

Dual Moving Average Crossover with a Fixed Stop Loss

Code Quant course library

Summary

The strategy applies a long-only moving average crossover to daily bars for a single stock. After enough bars are available to calculate both averages, it treats an upward cross of the shorter average over the longer one as an entry signal and buys when flat. A downward cross prompts liquidation of an existing position. The position size is based on the stated capital divided by the closing price, and the simulated trades use that bar’s close.

A separate protective rule exits a holding if the bar’s low reaches a fixed level below its average entry price, with the simulated sale priced at that stop level. The document shows how signals, position state, and profit updates are connected to a backtest interface, but it provides no performance results or cost model. Close-based entries and the stop fill assumption may not reflect achievable execution, and the example does not establish that the crossover has predictive value.

Key ideas

  • An upward crossover of the shorter moving average over the longer one triggers a long entry when flat.
  • A downward crossover closes an existing long position.
  • Position size is set from available capital and the entry bar’s closing price.
  • A stop loss exits when the bar’s low reaches the specified threshold below average entry price.
  • The example does not include reported results or an execution-cost model.

Tags

From a private course collection; the original is not published.